Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Aug 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript for Opening Popup Windows not Working in IE 8

    Dear friends,

    I am using a Javascript which perfectly worked in all relevant browsers, including IE6 and IE7. Its advantage has been to be able to specify the window-size + to decide, whether there should be scrollbars or the option to resize it. It is also fully standards-compliant.

    It opens a new popup window and is triggered via the rel="popup" or rel="popup nofollow" attributes in the specified external links, e.g.:

    Code:
    <a href="http://www.codingforums.com/" rel="popup">CodingForums</a>
    <a href="http://www.codingforums.com/" rel="popup nofollow">CodingForums</a>
    The code however does not do its job in IE8. It follows the link, but does so in the old window, not a new popup window, and thus recurs to standard behavior of links.

    Here is the Javascript-Code, included in the header:

    Code:
        var properties = { width: 900,
                           height: 450,
                           scrollbars: 'yes',
                           resizable: 'yes' };
        function popup(){
          var link = this.getAttribute( 'href' );
          var prop_str = '';
          for( prop in properties ){
            prop_str = prop_str + prop + '=' + properties[prop] + ',';
          }
          prop_str = prop_str.substr( 0, prop_str.length - 1 );
          var newWindow = window.open( link, '_blank', prop_str );
          if( newWindow ){
            if( newWindow.focus ) newWindow.focus();
            return false;
          }
          return true;
        }
        function setupPopups(){
          var links = document.getElementsByTagName( 'a' );
          for( var i=0; i<links.length; i++ ){
            if( links[i].getAttribute( 'rel' ) &&
                (links[i].getAttribute( 'rel' ) == 'popup' ||
                 links[i].getAttribute( 'rel' ) == 'popup nofollow')) 
    	links[i].onclick = popup;
          }
        }
        window.onload = function(){ 
          setupPopups();
        }

    Since I am not an expert, I would greatly appreciate help to make this efficent code workable in IE8.

    Thanks in advance!

    CodeMat
    Last edited by CodingMat; 08-25-2009 at 04:45 PM.

  • #2
    Banned
    Join Date
    Mar 2009
    Posts
    248
    Thanks
    3
    Thanked 68 Times in 66 Posts
    CodingMat:

    That's some code. Unobtrusive.

    This may not solve the problem. It could be a browser setting to "open all links in a new tab," that prevents a new window from opening, but, I noticed two things.
    Code:
     var newWindow = window.open( link, '_blank', prop_str );
          if( newWindow ){
            if( newWindow.focus ) newWindow.focus();
            return false;
          }
          return true;
    Since newWindow is assigned a value, it will ALWAYS be true. An empty string would cause it to be false.
    If the "link" is undefined, the code will just report an error and stop running.

    Your other links, the ones without the rel attribute won't be assigned an onclick event listener, so there's no need for a return true.

    This, '_blank', if memory serves is supposed to the "name" of the new window. It appears similar to the obsolete "target" attribute.

    Nevertheless, I can't recall that -- "name" -- ever being useful.

    I'd use an empty string for that parameter.

    So, I'd change that section to this:

    Code:
     var newWindow = window.open( link, '', prop_str );
     return false;
    The new window, if it opens, will be on-top, without setting focus() to it. Setting focus() to self, would make it a pop-under.

    Again, that may not solve the problem, and if it doesn't, I can't see anything that would be otherwise amiss.
    Last edited by 12 Pack Mack; 08-25-2009 at 01:52 AM.

  • #3
    New to the CF scene
    Join Date
    Aug 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Dear 12 Pack Mack,

    thanks so much for the incredibly quick reply. It gave me a full range of new insights. Applying your proposal, i.e. substituting the '_blank' with a '' and also changing the critical sectíon, did keep the script intact in all browsers, but did not - as you anticipated - change the stubborn behavior of IE8. I am at the moment checking, if browser settings which were at the default, could make a difference, but guess that this is not going to solve the issue, since anyway a script should work with the default settings.

    I think, since all other browsers take this script without any problems, even IE 7, we should feel free to put the burden of proof on that update. Your kind reply has also prompted me to go for the search term: "problems opening links in a new window with IE8" and there seem to come forward different complaints and proposals.

    At the moment, I will look ahead for new possible solutions and will check promising help, the internet might provide. Should I find a solution, I will gladly post it here.

    If logic applies, and why should it not, I might as well contact - just for fun - the support channels of our famous company, since they might feel honoured to know, what made the difference to their old product and to all other standard-compliant browsers.

    Thanks again!

    CodingMat

  • #4
    New to the CF scene
    Join Date
    Aug 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Dear friends,

    the issue has been resolved. The script in its original version and the one that 12 Pack Mack recommended works just fine in IE8 - final version. I had tried it in a standalone version which obviously was premature or deficient. Having installed the IE8 on an new system solved everything. This reminds us that using a final version or fresh installation is always a good idea to test in case of compatibility issues.

    Thanks anyway for the great help

    CodingMat


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •