Accessing the window object - problem with Internet Explorer (2)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mumpi
    New Member
    • Oct 2007
    • 3

    #1

    Accessing the window object - problem with Internet Explorer (2)

    From a documentlist the user activates links to see the document in a popup.

    The link (JSP):
    Code:
    <a href='javascript:var w=windowOpenDok("${docURLPDFFromTiff}","document",0.5,0.8);w.focus();'>
    The function:
    Code:
        function windowOpenDok (url,name,relWidth,relHeight) {
            var x = window.open (
                url,
                name,
                "height=" + Math.floor(screen.availHeight * relHeight) + ",width=" + Math.floor(screen.availWidth * relWidth) + ",resizable=yes,scrollbars=yes,toolbar=yes,status=yes",
                false
            );
            return x;
        }
    works as expected in Mozilla, Firefox but only partially in Internet Explorer. The command
    Code:
    w.focus();
    throws an error in IE (objectError) if the window is already there and contains no HTML neither XHTML but something loaded with mime-type "applicatio n/pdf". Bringing the existing window manually to foreground it shows the expected new document.

    What do I wrong? It looks like the reference to the window is ruined after loading the pdf.

    Many Thanks for any help.
    mumpi
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    #2
    Originally posted by mumpi
    From a documentlist the user activates links to see the document in a popup.

    The link (JSP):
    Code:
    <a href='javascript:var w=windowOpenDok("${docURLPDFFromTiff}","document",0.5,0.8);w.focus();'>
    The function:
    Code:
        function windowOpenDok (url,name,relWidth,relHeight) {
            var x = window.open (
                url,
                name,
                "height=" + Math.floor(screen.availHeight * relHeight) + ",width=" + Math.floor(screen.availWidth * relWidth) + ",resizable=yes,scrollbars=yes,toolbar=yes,status=yes",
                false
            );
            return x;
        }
    works as expected in Mozilla, Firefox but only partially in Internet Explorer. The command
    Code:
    w.focus();
    throws an error in IE (objectError) if the window is already there and contains no HTML neither XHTML but something loaded with mime-type "applicatio n/pdf". Bringing the existing window manually to foreground it shows the expected new document.

    What do I wrong? It looks like the reference to the window is ruined after loading the pdf.

    Many Thanks for any help.
    mumpi
    I am rewriting the code.
    Have a look over it.

    The link (JSP):
    Code:
    <a href='javascript:var w=windowOpenDok("${docURLPDFFromTiff}","document",0.5,0.8);if(typeof w) w.focus();'>
    The function:
    [CODE=javascript]
    function windowOpenDok (url,name,relWi dth,relHeight) {
    var x = window.open (
    url,
    name+Math.round (Math.random()* 1000),
    "height=" + Math.floor(scre en.availHeight * relHeight) + ",width=" + Math.floor(scre en.availWidth * relWidth) + ",resizable=yes ,scrollbars=yes ,toolbar=yes,st atus=yes",
    false
    );
    return x;
    }
    [/CODE]

    Good Luck.

    Kind regards,
    Dmjpro.

    Comment

    • mumpi
      New Member
      • Oct 2007
      • 3

      #3
      Thank you. The new code works because every call to the window.open function opens a new window. But I would prefer to reuse the same window and add the new document to the history. That enables the user to go forward and backward.

      Strange enough IE showed even with the test by typeof w an Error. In my german IE the error msg says "Mitglied nicht gefunden" at position ... typeof (here)w...

      Translated to english that could mean: w is there but the typeof asks a property of w which makes the thing crash?

      Consider that test. Instead of w.focus():
      Code:
      javascript:var w=windowOpenDok("${docURLPDFFromTiff}","document",0.5,0.8);alert (w.name);
      shows 'document' whether the window is new or was existing. No crash or error. It seems that typeof and focus() do not work if the window was already there when calling window.open(). Strange?!

      still helpless; many thansk for support.
      mumpi

      Comment

      • dmjpro
        Top Contributor
        • Jan 2007
        • 2476

        #4
        If you want to reuse the window.
        Then have a look at this code.

        [code=javascript]
        var new_win = null; //defined externally
        function new_window(url)
        {
        if(!typeof new_win) new_win = window.open(url ,"win_name"+Mat h.round(Math.ra ndom()*100),"wi n_style");
        else new_win.locatio n.href = url;
        }
        [/code]

        Have a try with this :-)
        Good Luck !

        Kind regards,
        Dmjpro.

        Comment

        • mumpi
          New Member
          • Oct 2007
          • 3

          #5
          Thank you for your proposal. Unfortunately it does not help.

          This more global variable new_win is ruined as soon as content donwloaded is mime-type "applicatio n/pdf" and the acrobat reader plugin is loaded. So the behaviour is very much the same as with the original scripts.

          I am afraid we have to look for another workaround. Tha main question being why is that window object ruined after it loaded acrobat plugin with a pdf-document in IE (and not in FF, Moz. etc.!)

          Comment

          • Sebastian Goetz
            New Member
            • Nov 2007
            • 2

            #6
            Hi Mumpi,

            we have exactly the same problem.
            We use a Java PDF-Engine to create PDFs on runtime. The same window should be used to display the results. When the user selects PDF output and the PDF is displayed by the PDF Plugin inside the browser window (and not by starting an AdobeReader instance), we get a Javascript error "Mitglied not found" whenfocusing the new window. As you mentioned this only happens when the window was already there and the content was PDF before.
            If the user has selected HTML output (as our pages can) the thing works as often as he likes.

            Did you find a solution for that?

            Regards

            Sebastian

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              Hi Sebastian, welcome to TSDN!

              Interesting problem. Have you tried loading the PDF in an iframe within the child window?

              Comment

              • Sebastian Goetz
                New Member
                • Nov 2007
                • 2

                #8
                Well, we just found a proprietary solution:

                It appears that though the window object itself seems to be broken, you may still close the window using the close() function. So have a look at this solution:

                Code:
                printwin = window.open(href, "Print");
                try
                {
                	// exception if adobe reader plugin version >= 7 is used
                	printwin.focus();
                }
                catch(e)
                {
                	printwin.close();
                	printwin = window.open(href, "Print");
                	printwin.focus();
                }
                This works for us an closes an open window if the focus() call hrows the exception and reopens it. The cost of the thing is that the content is loaded twice if the execption is thrown.

                Comment

                • acoder
                  Recognized Expert MVP
                  • Nov 2006
                  • 16032

                  #9
                  Thanks for posting your solution, even if it's not ideal. Hopefully it'll help someone with a similar problem.

                  Comment

                  Working...