<%@LANGUAGE=VBScript%> <%Option Explicit Response.Buffer = True Response.CacheControl = "Private" Response.Expires = -1 '--- We don't want this to be cached anywhere '---------------------------------------------------------------------------------------- '- ASP PrinterFriendly Application - Version 1.0 - 10 June 2005 '- Copyright © 2005 - Livio Siri (http://www.livio.net) - All Rights Reserved. '---------------------------------------------------------------------------------------- '--- print.asp - Make a link to this page from your page. '--- (ex. Printer friendly) '--- ASSUMES THAT YOUR PAGE HAS PRINTABLE CONTENT WITHIN TWO COMMENTS '--- '--- '--- Needs MSXML 3.0 and VBScript version 5 or above installed '---------------------------------------------------------------------------------------- If Request.ServerVariables("HTTP_REFERER") <> "" Then '--- if this didn't come from anywhere, ignore all. '--- Define variables Dim strContent, xml_http Dim objRegExp, strTitle , strBody, strAns Dim content_start, content_end, title_start, title_end Dim strThisDir '--- Perform the HTTP "GET" method via the XMLHTTP object to retrieve the page to be printed '--- Using the XMLHTTP object instead of something like FSO means that the ASP page '--- is actually executed and not just 'read' as a stream of characters. Set xml_http = Server.CreateObject("Microsoft.XMLHTTP") xml_http.Open "GET", Request.ServerVariables("HTTP_REFERER"), False xml_http.Send strContent = xml_http.responseText Set xml_http = Nothing '--- Get the Referer path for display purpose strThisDir = mid(Request.ServerVariables ("HTTP_REFERER"),1,inStrRev(Request.ServerVariables ("HTTP_REFERER"),"/") ) strBody = strContent '--- strBody contains now the whole HTML page if len(strBody) > 0 Then '--- get the page Title to be printed positioning references title_start = instr(LCase(strBody), "") + 7 title_end = instr(LCase(strBody), "") '--- get page Body to be printed positioning references content_start = instr(strBody, "") + 30 content_end = instr(strBody, "") End if '--- Avoid errors if no in the page If len(Title_start) < 1 AND len(Title_end) < 1 then strTitle = "No Title" Else strTitle = mid(strBody, title_start, title_end - title_start) End if '--- Avoid errors if strBody = nothing or your page doesn't have printable content within two comments If len(content_start) < 1 AND len(content_end) < 1 then strBody = "Nothing to print" Else '--- Get the page Body to be printed strBody = mid(strBody, content_start, content_end - content_start) '--- strBody contains now the part of the HTML page to be printed '--- Look for comments <!-- ... --> in the strBody and delete '--- Create built In Regular Expression object Set objRegExp = New RegExp objRegExp.IgnoreCase = True objRegExp.Global = True objRegExp.Pattern = "<!--(.*?)-->" strAns = objRegExp.Replace (strBody, "") strBody = strAns '--- strBody contains now the part of the HTML page to be printed without comments Set objRegExp = Nothing End if '--- Display the page Call display() End If '--------------------------------------------------------- Sub display() '--- Prepare and displays the HTML page part to be printed, '--- modify as you need to maintain the same "Style" of your page. %> <html><head> <title><%=strTitle%>

Printer Friendly Version of ""><%=Request.ServerVariables("HTTP_REFERER")%>"
Page Title: <%=strTitle%>


<%=strbody%>
<%Session.LCID = 1040%>
<% End sub %>