Print-funktion virker ikke i Explorer
Hej!Jeg har et problem, som jeg simpelthen ikke kan finde ude af. På et site er der en print-funktion bestående af en lille stump javascript-kode og lidt mere asp-kode. Funktionen virker med f.eks. Firefox men ikke Internet Explorer. Dvs. hvis man et vilkårligt sted på sitet klikker på "Print"-ikonet, åbnes et vindue med FORSIDEN af sitet - og ikke den pågældende side.
Som nævnt kan jeg ikke spotte fejlen, men håber at nogle måske har mødt lignende problemer og har et løsningsforslag.
--- start på javascript-koden ---
function D4ProPrintPage()
{
var strURL ;
var myWin;
strURL = "/print/print.asp" ;
myWin = window.open(strURL,'D4ProPrint','menubar=0,status=0,toolbar=0,scrollbars=1,resizable=1,dependent=1,titlebar=0,width=700,height=600');
myWin.focus();
}
--- slut på javascript-koden ---
--- start på ASP-koden ---
<!--#include virtual="/include/server/header.asp" -->
<!--#include virtual="/include/server/basedefs.asp" -->
<!-- Include Common files -->
<!--#include virtual="/include/server/common/common_getStyleSheetHTML.asp" -->
<!-- Include Error handling -->
<!--#include virtual="/include/server/common/HandleError.asp" -->
<%
' =============================
' Page scope variables
' =============================
dim m_lngSuccess
dim m_UserName
dim m_strStyleSheetHTML
dim m_printHTML
dim m_strYear
' =============================
' Site display texts
' =============================
dim m_appTitle
dim m_disclaimer
dim m_disclaimerText
dim m_copyright
dim m_copyrightText
dim m_print
' =============================
' Invokation of Main ()
' =============================
m_lngSuccess = main ()
if (m_lngSuccess <> SUCCESS) then
call HandleError ("Error executing the main method", "/Print/print.asp::main")
end if
' =============================
' Function definition area
' =============================
function main ()
' Define function scope variables
dim lngSuccess
on error resume next
' Get the browser type
lngSuccess = common_getStyleSheetHTML (m_strStyleSheetHTML)
if (lngSuccess <> SUCCESS) then
call HandleError ("Error executing the common_getStyleSheetHTML method", "/Print/print.asp::main")
end if
' Do the rest of the processing
Dim strPageContent
Dim strCallingPageURL 'URL to the calling page with arguments
strCallingPageURL = BuildURL()
m_printHTML = GetPage(strCallingPageURL)
' Get the site display texts
call getSiteDisplayTexts ()
call getYear (m_strYear)
end function
function getSiteDisplayTexts ()
dim strXMLFile
dim objXML
dim myNode
dim blnLoaded
set objXML = server.CreateObject("MSXML2.DomDocument.4.0")
' Load the XML file
strXMLFile = Server.MapPath ("/") & "/" & D4PRO_SITE_DISPLAY_TEXT_FILE
blnLoaded = objXML.load (strXMLFile)
if (blnLoaded) then
' Get the texts by using XPath
m_appTitle = objXML.selectSingleNode ("/MessageManager/Entry[@Name='AppTitle']/Value").text
m_disclaimer = objXML.selectSingleNode ("/MessageManager/Entry[@Name='PrintFooter_01']/Value").text
m_disclaimerText = objXML.selectSingleNode ("/MessageManager/Entry[@Name='PrintFooter_02']/Value").text
m_copyright = objXML.selectSingleNode ("/MessageManager/Entry[@Name='PrintFooter_03']/Value").text
m_copyrightText = objXML.selectSingleNode ("/MessageManager/Entry[@Name='PrintFooter_04']/Value").text
m_print = objXML.selectSingleNode ("/MessageManager/Entry[@Name='Article_08']/Value").text
else
m_appTitle = "text"
m_disclaimer = "Disclaimer: "
m_disclaimerText = "A/S disclaims any and all liabillity related to or arising out of use of the information contained in this site."
m_copyright = "© Copyright: "
m_copyrightText = "A/S"
m_print = "Print"
end if
set objXML = nothing
end function
function BuildURL()
Dim strPageName
Dim strForm
Dim strQueryString
Dim strServerName
Dim strServerPort
Dim strArgs
' Initialise
strArgs = ""
' Get the servername and port number
strServerName = Request.ServerVariables("SERVER_NAME")
strServerPort = Request.ServerVariables("SERVER_PORT")
' Get the name of to page to print, stored in cookies
strPageName = "/" & Request.Cookies (COOKIE_D4PRO_PRINT_PAGE)
strForm = Request.Cookies (COOKIE_D4PRO_PRINT_FORM_ARGS)
strQueryString = Request.Cookies (COOKIE_D4PRO_PRINT_QUERYSTRING_ARGS)
' Prepare the print argument, must always be present
strArgs = "?doPrint=" & DOPRINT_ARGUMENT
If(Len(strForm) > 0) Then
strArgs = strArgs & "&" & strForm
ElseIf(Len(strQueryString) > 0) Then
strArgs = strArgs & "&" & strQueryString
End If
' If other port than 80, append the port number
If (strServerPort <> "80") Then
BuildURL = "http://" & strServerName & ":" & strServerPort & strPageName & strArgs
Exit Function
Else
BuildURL = "http://" & strServerName & strPageName & strArgs
End If
End Function
Function GetPage(strPageURL)
Dim strUnStrippedContent
Dim objHTTPRequest
Set objHTTPRequest = Server.CreateObject("WinHttp.WinHttpRequest.5")
With objHTTPRequest
.open "GET", strPageURL, False
.send
End With
strUnStrippedContent = objHTTPRequest.responseText
Set objHTTPRequest = Nothing
GetPage = StripBetweenTags(strUnStrippedContent)
Exit Function
End Function
Function StripBetweenTags(strStripString)
Dim PosOfFirstTag
Dim PosOfSecondTag
Dim SizeOfTag
Dim LengthForMid
SizeOfTag = Len(strStripString)
PosOfFirstTag = InStr(strStripString, PRINT_FIRSTTAG)
PosOfSecondTag = InStr(strStripString, PRINT_SECONDTAG)
strStripString = Left(strStripString, PosOfSecondTag)
LengthForMid = Len(strStripString) - PosOfFirstTag
StripBetweenTags = Mid(strStripString, PosOfFirstTag, LengthForMid)
End Function
function getYear ( strYear )
dim objConvert
on error resume next
set objConvert = server.CreateObject ("D4ProUtil.Convert")
strYear = objConvert.DateTime (now(), "YYYY" )
set objConvert = nothing
end function
%>
<html>
<head>
<title><%=m_appTitle%></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- Style sheet -->
<%
Response.Write m_strStyleSheetHTML
%>
<!-- Style sheet -->
</head>
<body bgcolor="#FFFFFF" text="#000000">
<table width="645" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="/images/top-print.gif" width="645" height="73"></td>
</tr>
<tr>
<td align="right">
<table border="0" cellspacing="0" cellpadding="7">
<tr>
<td align="right"><a onfocus="blur()" href="java script:window.print()"><img src="/images/icon_print.gif" width="17" height="15"border="0"><%=m_print%></a></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<!--Main content starts here -->
<%
Response.Write m_printHTML
%>
<!--Main content ends here -->
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td class="related_text"><b><%=m_disclaimer%></b> <%=m_disclaimerText%><br>
<b><%=m_copyright%></b> <%=m_copyrightText & " " & m_strYear%>
</td>
</tr>
</table>
</body>
</html>
--- slut på ASP-koden ---
