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 11 of 11
  1. #1
    New Coder
    Join Date
    Nov 2005
    Posts
    85
    Thanks
    22
    Thanked 0 Times in 0 Posts

    Re-using a named window that subsequently contains third party content

    I am using:

    Code:
    win = window.open(windowURL, windowName);
    to open a new tab to display image pages in a landscape photography site.

    The image pages are available by clicking on links available in several different parts of the site. In order to prevent a proliferation of tabs I am using the same windowName each time an image page is requested. This way the existing tab is re-used. Everything works as required.

    However, I have found that in Opera 20 (in default configuration), if the user uses Speed Dial to load up their own page (not from my site) into the tab, then any subsequent requests for a page from my site (into the same tab) fail. There is no warning to the user and no error in the javascript console The page just does not load, presumably due to the browser giving priority to the Speed Dial page.

    I am looking for a way to work around this. I can’t use a different window name for my own pages because I am also accessing it elsewhere in another script. The ideal scenario would be for me to re-name the existing window once it no longer contained content from my site.

    Code:
    win.name = “new windowName”;
    This would preserve the users own page and allow my site to continue with the original name. However understandably, as far as I can tell, this can’t be accessed once a page external to my site occupies the tab.

    Thanks.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,310
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts
    Quote Originally Posted by Martins View Post
    The ideal scenario would be for me to re-name the existing window once it no longer contained content from my site.

    Code:
    win.name = “new windowName”;
    This would preserve the users own page and allow my site to continue with the original name. However understandably, as far as I can tell, this can’t be accessed once a page external to my site occupies the tab.

    Thanks.

    Not possible due to security constraints. You can't use JavaScript to get content from other sites. JavaScript can only get content from the same site as the page containing the script.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    New Coder
    Join Date
    Nov 2005
    Posts
    85
    Thanks
    22
    Thanked 0 Times in 0 Posts
    Thanks, I suspected that.

    Can you suggest any way that I can do it as the last page from my site unloads from the tab (before the third party one loads)? Obviously if I did it each time a page unloaded it would defeat the purpose.

    Do you think the way Opera deals with this is correct? I have not had the same experience with the other browsers.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,310
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts
    Quote Originally Posted by Martins View Post
    Thanks, I suspected that.

    Can you suggest any way that I can do it as the last page from my site unloads from the tab (before the third party one loads)? Obviously if I did it each time a page unloaded it would defeat the purpose.

    Do you think the way Opera deals with this is correct? I have not had the same experience with the other browsers.
    i don't use Opera so I cannot really say.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #5
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Where pages load is entirely under the browser owner's control so however their particular browser deals with it is correct for them.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    When you do this:

    Code:
    win = window.open(windowURL, windowName);
    and Opera stops it from working, is the win variable a valid window object or does it have a null value?
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #7
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    3,020
    Thanks
    56
    Thanked 566 Times in 563 Posts
    As far as I understand Opera in versions 12+ support the window.onbeforeunload event. You could maybe use that to change the window name just before it unloads, although as you say being that you only want to do it on the last one if the user is navigating away from your site, things may get sticky...

  • #8
    New Coder
    Join Date
    Nov 2005
    Posts
    85
    Thanks
    22
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by xelawho View Post
    As far as I understand Opera in versions 12+ support the window.onbeforeunload event. You could maybe use that to change the window name just before it unloads, although as you say being that you only want to do it on the last one if the user is navigating away from your site, things may get sticky...
    Thanks xelawho, but I don't think I have any way of knowing if the user is navigating away when window.onbeforeunload runs?
    Last edited by Martins; 04-01-2014 at 11:57 AM.

  • #9
    New Coder
    Join Date
    Nov 2005
    Posts
    85
    Thanks
    22
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by glenngv View Post
    When you do this:

    Code:
    win = window.open(windowURL, windowName);
    and Opera stops it from working, is the win variable a valid window object or does it have a null value?
    glenngv, thanks for the interest:

    If I alert ‘win’ after opening the tab:

    1) When the tab is first opened (i.e. no third party page present) the alert returns [object Window] in both FF and Opera..

    2) Once the third party page is loaded and I then open my tab again, the alert causes errors in both browser consoles although FF still displays my page:

    FF error - permission denied to access property ‘valueOf’

    Opera error - Uncaught SecurityError: Blocked a frame with origin "http://localhost" from accessing a frame with origin "swappedout://". The frame requesting access has a protocol of "http", the frame being accessed has a protocol of "swappedout". Protocols must match.

    So it seems to be breaching protocols in both browsers but still displays my page in FF.

    3) In the DOM for 'win' (using Firebug):

    FF - Window ‘my url’

    Opera - Window { }
    (hovering over this brings up ‘undefined’)

    So the difference is no url associated with ‘win’ in Opera.

    Appreciate any suggestions.

    Thanks.

    Martin

  • #10
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    I think your only choice is to change your window name target when a third party page is loaded. You do this by doing a try/catch while accessing any properties or methods of the win object, if it throws exception, then it means a third party page is loaded.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • Users who have thanked glenngv for this post:

    Martins (04-02-2014)

  • #11
    New Coder
    Join Date
    Nov 2005
    Posts
    85
    Thanks
    22
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by glenngv View Post
    I think your only choice is to change your window name target when a third party page is loaded. You do this by doing a try/catch while accessing any properties or methods of the win object, if it throws exception, then it means a third party page is loaded.
    Thanks Glenn, the problem is that I need to keep the same name for use with another script. Where a third party page is open, I settled for opening mine with a temporary name and then renaming it to the original name onload. This works with opera and also maintains the users third party page in all the browsers. Presumably, I end up with two windows with the same name, but it does not seem to be an issue. Cheers.


  •  

    Tags for this Thread

    Posting Permissions

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