Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

window.Print() not working.

 
Ashwani Yadav
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using two frames, in my first frame my "Print" button is there and from that button I want to print the another frame's document(HTML CSS).
So for that I have written the following Function:
function printReport()
{
parent.Main.focus();//"Main is my second Frame's name which I want to Print.
window.print();
}
The above function works well in IE but in netscape 6, nothing happens , it also doesn't give me any error message.
If any one have any idea about my problem please respond.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Quoted from O'Reilly Javascript book (the rhino book)
Simulates a click on the browser's Print button. IE5 and Netscape4 only

Looks like you're out of luck
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this:

It is tested in Netscape 7 Priview Release 1, Netscape 4.79 and Internet Explore 6 sp1
/Rene
 
Ashwani Yadav
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Thanks for the quick response, but by using this function I am getting access denied arror.
As my Print button in upper frame and the document which I want to print is lower one(i.e. main--Frame name).
 
Ashwani Yadav
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya now print pop up is opened on call of this function but it prints only the upper frame where as i am giving name of lower frame to print.
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is how I did it:
index.html

top.html

main.html

Is this the way you are doing it too or almost to way?
/Rene
 
Ashwani Yadav
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
As said by you that following code is working, although I have seen ur code also that is working fine.
Actually in My second frame i.e. Main, I am generating Report in HTML CSS and that i want to be printed.
In the following function it is not going beyond
parent.Main.focus().
Could you please suggest me something regarding this.
---------------------------------------
<script language="javascript">
function printReport()
{
alert("Before if condition");
if (window.print)
{
alert("After if condition");
parent.Main.focus();
alert("After focus----");
parent.Main.print();
alert("Over");
}
}
</script>
------------------------------------
 
Ashwani Yadav
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The above witten function gives error "Access denied" when the frame which I am printing conatins HTML CSS document.
Does any body knows abot this?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic