JavaScript document.write(): How to view the HTML?
How to view the html generated by Javascript document.write() command?
When you use the JavaScript document.write() code to output something to the browser, it does not give you a friendly way to debug your JavaScript. If you view source on the page, browser shows you the JavaScript code again; it does not show you what your document.write() results in.
For example, if your JavaScript code is something like the uggly stuff below:
v_temp='<div '+(v_nS4?"name":"id")+'=v_container style="position:'+v_position+'; top:'+v_top+'px; left:'+v_left+'px; width:'+v_width+'px; height:'+v_height+'px; background:'+v_bgColor+'; layer-background'+ (v_bgColor.indexOf("url(")==0?"-image":"-color")+': '+v_bgColor+';clip:rect(0,'+v_width+','+v_height+',0); overflow:hidden">';for(v_i=0; v_i'+(v_content[v_i][0]!=''?' < a href="'+v_content[v_i][0]+'" target="'+v_content[v_i][2]+'" class=vnewsticker'+(v_pauseOnMouseOver?" onmouseover=\'if(v_canPause&&v_count>1) {clearTimeout(v_TIM);v_cl=1}\' onmouseout=\'if(v_canPause&&v_count>1&&v_cl) v_TIM=setTimeout(\"v_canPause=0;v_slide(); v_cl=0\","+v_timeout+")\'":"")+'>':' 1) {clearTimeout(v_TIM);v_cl=1}\' onmouseout=\'if (v_canPause&&v_count>1&&v_cl) v_TIM=setTimeout(\"v_canPause=0;v_slide(); v_cl=0\","+v_timeout+")\'":"")+'>') +v_content[v_i][1]+ (v_content[v_i][0]!=''?'</a >':'</span >')+'</div >'; v_temp+='</div >';
document.write(v_temp);
it can be really hard if you want to know what HTML code your document.write() actually sends to the page. Martin Spedding wrote a nice little script for this at his blog (weblogs.asp.net/mspedding). See the following code.
<html>
<body>
<script janguage="javascript">
document.write("This is a" + "concatenation test" + "<BR>");
function newWin(){
ven = window.open('','_blank');
var results =document.documentElement.innerHTML;var match = "<";var re = new RegExp("<", "g");var newresults = results.replace(re, "<");ven.document.write(newresults);}
</script>
<a href="#" onClick="javascript:newWin();">See the HTML code generated by document.write() here.</a>
</body>
</html>
Note, the function newWin() and the a href are the important pieces. Place your JavaScript code in place of the document.write line.
Discuss this article or this topic in our discussion forum:
How can I link to this web page?
It is easy, just include the code provided below into your HTML code.
Where can I get some help with this?
Copyright © 2010 Maxi-Pedia http://www.Maxi-Pedia.com
Reproduction without written permission from Maxi-Pedia is prohibited.
All articles are protected by copyright and have been archived at a national library.
Linking to Maxi-Pedia pages is permitted provided that the links are clearly acknowledged. Thank you.
Delicious
Digg
StumbleUpon
Furl
Facebook
Google
Yahoo

