Popup not working in Firefox/IE?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jdgregson
    New Member
    • Oct 2010
    • 3

    Popup not working in Firefox/IE?

    After finishing this proof-of-concept, I realized that it only works in Google Chrome, the browser I was using.

    I'm not going to try to explain how it works, because it's pretty much noobie scripting.

    But basically, in Chrome, it does exactly what it's supposed to and writes copyUrlWindowTe xt, copyUrlWindowEx p, copyUrlWindowCS S and copyUrlWindowSc ript to a new window called copyUrlWindow. But in Firefox and IE, I'm left with just a blank popup.

    Here is the code:

    Code:
    <html>
    	<head>
    		<script type="text/javascript">
    
    
    function urlWindow()
    {
    copyUrlWindow=window.open('','','width=300,height=200');
    
    copyUrlWindowScript=document.createElement("SCRIPT");
    copyUrlWindowScript.setAttribute("src", "http://developer.jdgregson.com/projects/current/urlcopy/urlScript.js");
    
    copyUrlWindowText=document.createElement("INPUT");
    copyUrlWindowText.setAttribute("type", "text");
    copyUrlWindowText.setAttribute("id", "copyArea");
    copyUrlWindowText.setAttribute("value", "ERROR");
    copyUrlWindowText.setAttribute("onclick", "selectText('copyArea')");
    copyUrlWindowText.setAttribute("size", "40");
    
    copyUrlWindowExp=document.createElement("P");
    copyUrlWindowExp.innerHTML="Click the link in the box to select it. Press Control + C to copy it.";
    
    copyUrlWindowCSS=document.createElement("LINK");
    copyUrlWindowCSS.setAttribute("rel", "stylesheet");
    copyUrlWindowCSS.setAttribute("href", "http://developer.jdgregson.com/projects/current/urlcopy/popup.css");
    
    
    
    
    copyUrlWindow.focus();
    
    copyUrlWindow.document.head.appendChild(copyUrlWindowScript);
    
    copyUrlWindow.document.head.appendChild(copyUrlWindowCSS);
    
    copyUrlWindow.document.body.appendChild(copyUrlWindowExp);
    
    copyUrlWindow.document.body.appendChild(copyUrlWindowText);
    
    copyUrlWindow.document.body.setAttribute("onfocus", "getUrl();");
    
    }
    
    
    		</script>
    	</head>
    	<body>
    
    		<input type="button" value="Copy URL" onclick="urlWindow()" />
    
    	</body>
    </html>
    Does anyone have any idea why it doesn't work right in IE and Firefox?

    Here is a link to the project online: http://developer.jdgre gson.com/projects/current/urlcopy/PopUpParent.htm l
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    is there anything in the error console?

    PS. line #40, why not using proper event handling? copyUrlWindow.d ocument.body.on focus = getUrl;

    Comment

    • jdgregson
      New Member
      • Oct 2010
      • 3

      #3
      Firefox's error console returns two errors each time the button is clicked. Here they are:

      Error: uncaught exception: [Exception... "Component returned failure code: 0x8000ffff (NS_ERROR_UNEXP ECTED) [nsIPrefBranch.c learUserPref]" nsresult: "0x8000ffff (NS_ERROR_UNEXP ECTED)" location: "JS frame :: chrome://dotnetassistant/content/bootstrap.js :: BootStrapDotNet AsssitantExtens ion :: line 52" data: no]



      Error: copyUrlWindow.d ocument.head is undefined
      Source File: http://developer.jdgregson.com/proje...pUpParent.html
      Line: 32


      I'm not sure the first one has anything to do with it. In Firefox, after the button is clicked and the new window created, it is completely blank, except for the <!DOCTYPE><html ><head> tags the the browser puts in automatically.

      Comment

      • jdgregson
        New Member
        • Oct 2010
        • 3

        #4
        Okay, I changed it from

        copyUrlWindow.d ocument.head.ap pendChild(copyU rlWindowScript) ;

        copyUrlWindow.d ocument.head.ap pendChild(copyU rlWindowCSS);

        to

        copyUrlWindow.d ocument.body.ap pendChild(copyU rlWindowScript) ;

        copyUrlWindow.d ocument.body.ap pendChild(copyU rlWindowCSS);

        and it works great in Chrome and Firefox, but still no dice in IE.

        Comment

        • Dwight Vietzke

          #5
          Hi JD,

          Are you getting something like this:

          Error: No such interface supported

          I am trying to do the same thing, that is, add a link to a stylesheet dynamically for my just created popup. Works in everything but IE (of coarse). But this:

          win.document.he ad = win.document.he ad || win.document.ge tElementsByTagN ame('head')[0];
          win.document.he ad.appendChild( node);

          ...worked for me in FF, Opera and Chrome. My pages are in HTML5, but the getElementsByTa gName('head')[0] may still be necessary for it to work in all browsers.

          Apparently IE won't allow you to dynamically add link tags to the head section of a popup from the opener window. Why, I don't know? I can add the link tag(s) to my 'pop_page' html code, then do this:

          var pop_d = pop_win.documen t;
          pop_d.open();
          pop_d.write(pop _page);
          pop_d.close();

          ...and they work, but not later. God, I hate IE!

          Comment

          Working...