Skip to content

Instantly share code, notes, and snippets.

@esprehn
Created November 19, 2015 06:43
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 esprehn/fb0d1c1e8942762497e7 to your computer and use it in GitHub Desktop.
Save esprehn/fb0d1c1e8942762497e7 to your computer and use it in GitHub Desktop.
Create registration context
var createNewRegistrationContext = (function() {
// This is slow and means using more memory keeping the iframe window alive,
// but there's no other way to get a fresh registration context. :(
var iframe = document.createElement("iframe");
iframe.style.display = "none";
document.documentElement.appendChild(iframe);
var lastDocument = iframe.contentDocument;
return function() {
// This keeps nesting template documents to create new registration
// contexts.
lastDocument = lastDocument.createElement("template").content.
ownerDocument.implementation.createHTMLDocument(null);
return lastDocument;
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment