2012-04-03
today's implementation of a demand, the theme is to browse the page generated HTML saved, record access URL, hang on the company's website to do the case. The first busy N-long is to search for HTML-generated JS function. What IE comes with the Activex,js plugin, JS winow.print (); Function call printer print page and so the final result is how to do it. At the end of the day, you'll see a question on the stackoverflow.com website, which is also related to generating HTML.
The Cow Man solution is as follows:Using jquery//See this sentence I suddenly sign language, such a simple way I can't think ofvar dom = $ ("HTML"). html ();//Get the contents of the HTML node//alert (DOM); $.post ("Exportcase.do", {dom:$ ("HTML"). html ()});//The server accepts the request processing and outputs the HTML content as xxx.htm to the path you want to specify
Finally, I draw on this, wrote a perfect JS function:<Scripttype="Text/javascript"><!--function exportcase (){try{varfilename = prompt ("Please enter the HTML file name to generate:",""); if(Undefined==filename | |""==filename){NewBoxy ("<div style= ' width:300px;height:100px; ' ><p> file name is empty, build failed </p></div> ", {Title:' message prompt '}); return; } //alert ("Export filename:" +filename); $j. Ajax ({ Type:"POST",URL:"Exportcaseajax.do",Cache:"false",Data:{ "Dom": $j ("HTML"). HTML (), "FileName": filename, "Rnd": Ajaxrandom () },DataType:"JSON",Success:function(data, Textstatus){if(!isundefined (data)){varcode = Data.code; //alert (code); if(code==0){vard = data.data; New Boxy ("<div style= ' width:400px;height:100px; ' ><p> "+d.name+"file generation succeeded!</p><p> access path is:</p><p> "+d.url+"</p></div>",{Title:' message prompt '}); } else {NewBoxy ("<div style= ' width:300px;height:100px; ' ><p> "+data.data+"</p></div>",{Title:' message prompt '}); } } } }); }catch(ERR){} }//--></Script>The server handles the action code I will not post it, with I/O on the line.
JS makes the Web page an HTML save access