window.onload being ignored for child in IE

B

Beni Rose

I'm trying to open a new window using window.open and then print that
window once it's loaded. It works fine in Firefox, but not at all in
IE. No matter what I put in my onload, it gets ignored. Here's the
code:

function openPrintPage(loc)
{
var printWin = window.open(loc+'?
dl=false','printpage','width=600,height=800,location=no,menubar=no,directories=no,status=no,toolbar=no,scrollbars=yes,resizable=yes');
printWin.onload = function()
{
printWin.print();
}
}

Even if I just put an alert in that printWin.onload, it doesn't do
anything. My only guess is that the page has loaded before the onload
function gets assigned, but I can't figure out a way to assign it
otherwise.
 
H

Henry

I'm trying to open a new window using window.open and then
print that window once it's loaded. It works fine in Firefox,
but not at all in IE. No matter what I put in my onload, it
gets ignored. Here's the code:

function openPrintPage(loc)
{
var printWin = window.open(loc+'?
printWin.onload = function()
{
printWin.print();
}

}

Even if I just put an alert in that printWin.onload, it doesn't
do anything. My only guess is that the page has loaded before
the onload function gets assigned, but I can't figure out a way
to assign it otherwise.

In reality IE assigns an onload value as a page loads and when that
page does not define an onload handler of its own (is a script or as
an attribute in the opening body tag) it ends up assigning the null
value to onload. Thus you just cannot successfully assign to the
onload property of the object returned from - window.open -.
 
S

SAM

Beni Rose a écrit :
I'm trying to open a new window using window.open and then print that
window once it's loaded. It works fine in Firefox, but not at all in
IE. No matter what I put in my onload, it gets ignored. Here's the
code:

function openPrintPage(loc)


perhaps ... :


function openPrintPage(loc)
{
var attr = 'width=600,height=800,'+
'location=no,menubar=no,directories=no,'+
'status=no,toolbar=no,scrollbars=yes,resizable=yes'
if(typeof printWin == 'undefined' || printWin.closed)
{
printWin = window.open('','',attr);
}
printWin.onload = printWin.print; // or = window.print;
printWin.location = loc+'?dl=false';
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,738
Latest member
JinaMacvit

Latest Threads

Top