views:

920

answers:

1

Here's my scenario:

I have a page containing several links; each link is meant to open another window containing a pdf. The catch is, I can't have that window directly go to the PDF because I do not want to make it apparent to the end user the PDF is located on another domain, and I need to name the PDF differently than how it would regularly show up.

So then I have two pages: One is blank, and only contains a frame to be used for displaying the pdfs:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
    <head>
     <title>[PDF]</title>
    </head>
    <frameset>
     <frame id="pdfFrame">
    </frameset>
</html>

And on the page with the links, I have the following function that calls this page (we'll call the above page "pdf.html"):

function OpenWindow(pdfTitle, pdfLocation)
{
    var myWindow = window.open("pdf.html", "", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=700,height=600");

    myWindow.document.title = pdfTitle; 
    myWindow.document.getElementById('pdfFrame').src = pdfLocation;
}

For the most part, this seems to work fine; however, on occasion the pop up window will not be loaded prior to the lines above that setup the title/frame source, and it will crash (or not load properly, at least).

My question is, is there a simple way for me to add in some sort of blocking call after opening the window, to wait until we're ready to run this code?

Thanks!

+3  A: 

You can't really block until it's loaded but you can set an event in the popup, like this:

myWindow.onload = function()
{
    document.title = pdfTitle;
    document.getElementById('pdfFrame').src = pdfLocation;
}
Greg
I had a similar idea earlier and tried the same thing; however, it didn't work... I'm thinking this function is getting created in the parent window after the child has loaded
John
You could always poll it for a variable set onload...
Greg