'; //write the text to iframe to access it later via dom object if (document.all) { var iframe_doc = html2convert.document; } else { var iframe_doc = document.getElementById('html2convert').contentWindow.document; } if (document.all && ie_version < 5.5) { //ie5.0 could generates onload event earlier then loading is actually finished iframe_doc.onload = setTimeout('parse_iframe()', 1); } iframe_doc.open(); iframe_doc.write(text2set); iframe_doc.close(); } //convert html to xhtml and write to destination textarea function parse_iframe(){ if (!can_parse) return; var page_mode = get_page_mode(); //determine source dom object if (document.all) { var iframe_doc = html2convert.document; } else { var iframe_doc = document.getElementById('html2convert').contentWindow.document; } if (page_mode) { var source_obj = iframe_doc; } else { if (document.all) { var source_obj = iframe_doc.body; //html fragment ie } else { var source_obj = iframe_doc.documentElement; //html fragment mozilla } } var xhtml_content = get_xhtml(source_obj, lang, encoding); if (document.all) { html2convert_result.value = xhtml_content; } else { document.getElementById('html2convert_result').value = xhtml_content; } } //allow to convert if the whole document is loaded only function init(){ can_parse = true; } function get_page_mode(){ if (document.all) { return page_mode.checked; } else { return document.getElementById('page_mode').checked; } }


Home } Generators } HTML2XHTML



The H2X converter generates a well-formed XHTML string from an HTML DOM object. H2X could be used in content management systems, online WYSIWYG HTML editors or any other application to produce well formed XHTML 1.0 code.
html:

xhtml:


 

The JavaScript Source: BG Effects: HTML2XHTML

Simply click inside the window below, use your cursor to highlight the script, and copy (type Control-c or Apple-c) the script into a new file in your text editor (such as Note Pad or Simple Text) and save (Control-s or Command-s). The script is yours!!!

    

Did you use this script?  Do you like this site?  Please link to us!

Add a comment, suggestion, or correction
[For questions about usage, consult the Notes tab above or visit the JavaScript forum. Do not include more than two (2) lines of code in your comments. If you have suggestions or corrections, you can submit them to us.]

    
   
       
[optional]
 
[optional]

   

Comments feed Comment Feed RSS 2.0

Sign up for the Web Development Daily Newsletter

internet.com Privacy Policy
We'll send this script to you!

(just click "Send it!" once!)