Using HTTP components to print pages

Source: Internet
Author: User
Tags chr comment tag html tags
Print | Page HTTP component, I know there are asphttp,asptear and so on, here we want to use is Bill's XMLHTTP, if you do not have the machine, you can download

http://www.microsoft.com/data Download mdac2.6

http://msdn.microsoft.com/workshop/xml/index.asp Download MSXML

Like most of the pages we see, for example, a news specific content page, the page has a connection called to print this page, point in later, not immediately print (of course, I mean the selective printing), but there is a remove some of the tail-related information of the file, there may be a print connection, Maybe you should do it yourself.

Our idea is to use the HTTP component to get the information on the page and then use some methods like we can use regular expressions to isolate what we want and what we don't want. We use HTML tags to get rid of what we don't want, like:

<!--START Ppomit-->
<table>
<tr>
<td><a href= "/home" >home page</a></td>
</tr>
<tr>
<td><a href= "/support" >support</a></td>
</tr>
<tr>
<td><a href= "/contact" >contact us</a></td>
</tr>
<tr>
<td><a href= "/products" >Products</a></td>
</tr>
</table>
<!--end Ppomit-->

Of course, you also need to provide a print connection, which we do with JScript.
<script language= "JavaScript" >
<!--hide from old browsers
PPB and PPE are the start and end of the dynamic link
Window.location.href'll refer to the current URL of the page
It's nice to make it open in a new window too! i.e. Target=_blank

var ppb = "<a href=/print/printpage.asp?ref=";
var PPE = "Target=_blank>print this page</a><br>";
document.write (ppb + window.location.href + PPE);

End-->
</script>

Here we pass a current path to the printed page, please see the code for the stay

Let's give you a simple example of XMLHTTP.
<%

Function gethtml (strURL)
Dim objXmlHttp, Strreturn
Set objxmlhttp = Server.CreateObject ("Microsoft.XMLHTTP")

Objxmlhttp.open "Get", strURL, False
Objxmlhttp.send

Strreturn = Objxmlhttp.responsetext
Set objXmlHttp = Nothing

gethtml = Strreturn
End Function

' Write it:
Response.Write gethtml ("http://www.topcoolsite.com/")

' Download it:
Response.ContentType = "Application/x-msdownload"
Response.AddHeader "Content-disposition", "filename=something.asp"
Response.BinaryWrite gethtml ("http://www.topcoolsite.com/")

%>
Running the above code will be able to see my personal site,:

Next we're going to start with a printpage.asp
Once you've inserted the annotation tag in the right place, the only thing left is the code.

<%
Option Explicit
Response.Buffer = True

' Define variables, regular expressions, XMLHTTP, paths

Dim refpage, objXmlHttp, RegEx

Refpage = Request.QueryString ("ref")
If Refpage = "" Then
Response.Write "Response.End
End If

Set objxmlhttp = Server.CreateObject ("Microsoft.XMLHTTP")


Objxmlhttp.open "Get", Refpage, False
Objxmlhttp.send

Refpage = Objxmlhttp.responsetext

Set RegEx = New RegExp
Regex.global = True


' Use regular expressions to work
Regex.pattern = "<!--START ppomit-->"

Refpage = Regex.Replace (Refpage, (Chr (253)))

Regex.pattern = "<!--end Ppomit-->"

Refpage = Regex.Replace (Refpage, (Chr (254)))

Regex.pattern = Chr (253) & "[^" & Chr (254) & "]*" & Chr (254)

Refpage = Regex.Replace (Refpage, "")

Set RegEx = Nothing
Set objXmlHttp = Nothing

Response.Write Refpage
%>

If your version of the script engine is 5.5 or more
The pattern of regular expressions can be written like this

<!--START Ppomit--> (. *?) <!--end Ppomit-->

Right, but also to standardize your HTML code, remember to close the corresponding, such as &LT;TABLE&GT;&LT;/TABLE&GT, otherwise it will fool ... : You can put your head, navigation bar, and so on in a separate file, so it's easy to insert a comment tag.



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.