Changing the window opened with the javascript "window.open ()" function

Here's my script:

I have a page that contains several links; each link is for opening another window containing the pdf. The catch is, I can't get this window to go directly to the PDF because I don't want the end user to indicate that the PDF is on a different domain and I need to name the PDF differently than it would regularly show.

So, I have two pages, one is empty and only contains a frame that will be used to display the pdf files:

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

      

And in the page with links, I have the following function calling that page (let's 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 works fine; however, sometimes the popup won't load before the lines above that set the header / frame source and it will crash (or not load properly, at least).

My question is, is there an easy way for me to add some kind of blocking call after the window is open, wait until we can run this code?

Thank!

+1


source to share


1 answer


You cannot block before loading, but you can set an event in the popup, like this:



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

      

+3


source







All Articles