JS makes the Web page an HTML save access

Source: Internet
Author: User

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>&nbsp;&nbsp;"+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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.