2

here i am having working code for printing and print preview,but its not working in Mozilla. plz let me know that how i make it to work in mozilla also..i want the print preview as same like the irctc website is having.

<html>
<head>
<title>Print Preview</title>
<style type="text/css">
 @media print {
.noPrint {
    display:none;
  }
}
</style>
<script>
function printpr()
{
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>
<form runat="server">
<asp:radiobutton ID="Radiobutton1" class="noPrint" runat="server"></asp:radiobutton>
<asp:textbox ID="Textbox1" runat="server"></asp:textbox>
<asp:checkboxlist ID="Checkboxlist1" class="noPrint" runat="server">
    <asp:ListItem>gsdghsg</asp:ListItem>
    <asp:ListItem>ggsgh</asp:ListItem>
    <asp:ListItem Value="gdfgg">gfghghgf</asp:ListItem>
    <asp:ListItem></asp:ListItem>
    </asp:checkboxlist>
<div class="noPrint"><asp:textbox ID="Textbox2" runat="server"></asp:textbox></asp:checkboxlist></div>
<input type='button'class="noPrint" value="Print Preview" onclick="printpr();">
</form>
</body>
</html>

1 Answer 1

1

In mozilla since recently items with some id are not automatically exposed into global namespace (window object).

You need to define a variable:

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);

var WebBrowser1 = document.getElementById('WebBrowser1');

WebBrowser1.ExecWB(OLECMDID, PROMPT);
WebBrowser1.outerHTML = "";
Sign up to request clarification or add additional context in comments.

3 Comments

k. actly the above code is wrking in IE7..cn u give me some working sample...m new to this javascript...
Ok, I updated my code. But I'm afraid this OBJECT will work in IE only. And you need to search completely different way, how do that.
your code is not working in both IE and Firefox getting error in IE as document is not defined

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.