Skip to content

Instantly share code, notes, and snippets.

@wvuwebgist
Created January 18, 2018 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wvuwebgist/37ae4fc284de7507001d34e987e125e9 to your computer and use it in GitHub Desktop.
Save wvuwebgist/37ae4fc284de7507001d34e987e125e9 to your computer and use it in GitHub Desktop.
Add a `title` Attribute to Wufoo's <iframe> and remove superflous presentational attributes.
// --- Add a `title` Attribute to Wufoo's <iframe> and remove ---
// --- superflous presentational attributes ---
// We have to wait until the <iframe> is built to add stuff to it;
// hence, the reason for using the MutationObserver API. It listens
// for when the node is finished building, then we can add & remove stuff.
var wufooOptions = {
wufooId: 'wufoo-xilwg7v0n5ncc2', // The id of the <div> Wufoo gives you for their JS form embed
titleContent: 'Cast your vote by selecting a hat.' // The content for your title attribute
};
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation, index) {
if (index > 0){
// stops further observing of changes
observer.disconnect();
} else {
var wufooIframeId = mutation.addedNodes[0].id;
var wufooIframe = document.getElementById(wufooIframeId);
wufooIframe.setAttribute('title', wufooOptions.titleContent);
// Remove attributes listed in the following array:
var removeTheseAttributes = ['frameborder','style','scrolling','allowtransparency'];
removeTheseAttributes.forEach(function(attr,index){
wufooIframe.removeAttribute(attr);
});
}
});
observer.disconnect();
});
// Listen to all changes to the child node of the <div> supplied by Wufoo
var targetNode = document.getElementById(wufooOptions.wufooId);
observer.observe(targetNode, { childList: true });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment