Link to home
Start Free TrialLog in
Avatar of ghmurphy
ghmurphy

asked on

Get Javascript Print Preview working in Firefox.

I have a Javascript print preview which works wonderfully in IE.  I get this Javascript error when I try to run it in Firefox.  I would like to get it working in firefox or another script which does the same thing and I can use coldfusion to send the client to the appropriate script.

Here is the Firefox error message.
document.body.insertAdjacentHTML is not a function

Here is the IE code which works great in IE.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script>
function printpreview()
{
var OLECMDID = 7;
/* OLECMDID values:
* 6 - print
* 7 - print preview
* 1 - open window
* 4 - Save As
*/
var PROMPT = 1; // 2 DONTPROMPTUSER
var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
WebBrowser1.ExecWB(OLECMDID, PROMPT);
WebBrowser1.outerHTML = "";
}
</script>

</head>
<body>
<a href="<cfoutput>#CGI.SCRIPT_NAME#</cfoutput>" onclick="printpreview();">x</a>
</body>
</html>

ASKER CERTIFIED SOLUTION
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ghmurphy
ghmurphy

ASKER

I tried your code but I still get an error in Firefox that says Webrowser1 is not defined.  I am just looking for another script that has the same functionality that will work in Firefox.  I don't want to reinvent the wheel.
You cannot reinvent it, because there is NO print preview wheel in Mozilla that can be controlled by script.