-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.html
27 lines (25 loc) · 988 Bytes
/
script.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<script type="text/javascript">
const fieldsToHide = ["name", "email", "subject", "description"];
function hideZendeskFields() {
var zendeskIframe = document.getElementById("webWidget").contentDocument;
var fields = zendeskIframe.querySelectorAll("input, textarea");
// description is of type textarea
fields.forEach((field) => {
if (fieldsToHide.includes(field.name)) {
field.parentElement.style.display = "none"; // hides the parent div (thus including the label!)
}
});
}
// Instead of setInterval, zE('webWidget:on', 'open', callback) can be used
// however, that won't get triggered if your Zendesk form is shown on page load
const checkZendeskLoaded = setInterval(function () {
if (
document
.getElementById("webWidget")
?.contentDocument?.querySelectorAll("input")?.length > 0
) {
hideZendeskFields();
clearInterval(checkZendeskLoaded);
}
}, 100); //check every 100 ms
</script>