Skip to content

Instantly share code, notes, and snippets.

@os0x
Forked from snaka/HTMLStringToDOM.js
Created August 8, 2009 14:55
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 os0x/164430 to your computer and use it in GitHub Desktop.
Save os0x/164430 to your computer and use it in GitHub Desktop.
シンプルな HTMLPaser / scriptを削る正規表現はjAutoPagerizeから
function HTMLStringToDOM(str){
var html = String(str).replace(/<script(?:[ \t\r\n][^>]*)?>[\S\s]*?<\/script[ \t\r\n]*>|<\/?(?:i?frame|html|script|object)(?:[ \t\r\n][^<>]*)?>/gi, ' ');
var htmlDoc = document.implementation.createHTMLDocument ?
document.implementation.createHTMLDocument('HTMLParser') :
document.implementation.createDocument(null, 'html', null);
var range = document.createRange();
range.selectNodeContents(document.documentElement);
htmlDoc.documentElement.appendChild(htmlDoc.importNode(range.createContextualFragment(html),true));
return htmlDoc;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment