Web Analytics Made Easy -
StatCounter window.opener.location on safari - CodingForum

Announcement

Collapse
No announcement yet.

window.opener.location on safari

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • window.opener.location on safari

    Hello,
    I am trying to use the window.opener.location code from a link on my popup window to change the webpage in the window that opened my popup. It works on ie/firefox, but doesnt work on safari.

    Code:
    function changepage(id) {
    window.opener.focus();
    //window.opener.location('http://www.mysite.com/index.php?id='+id);
    window.opener.location.pathname = 'index.php?id=' + id;
    self.close();
    return false;
    }
    Now i've tried the link with both <a href="#" onClick="return changepage(35);"> and <a href="javascript:changepage(32);"> but safari doesnt want to touch the opener page. Do you know of any workaround/hack to get this to work? If not, is there a way to check to see if the user has safari and change the code to opening the page in a new window?


    Thanks a lot

  • #2
    try

    window.opener.location.href="url";
    or
    window.opener.window.location.href="url";
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

    Comment


    • #3
      second one works great. thanks a lot.. i dont see why there is no documentation of this issue online saying that that code is the only one to work on safari....

      Comment


      • #4
        You have to check if the opener is still open, otherwise an error will occur.

        Code:
        function changepage(id) {
          if (opener && !opener.closed){
            opener.location.href = "test.htm";
            opener.focus();
          }
          else {
            window.open("test.htm", "_blank");
          }
          window.close();
          return false;
        }

        Alternative solution:

        Code:
        function changepage(id) {
          var w = window.open("test.htm", "[i]WindowNameOfOpener[/i]");
          w.focus();
        }
        If the opener is in a frame or iframe, WindowNameOfOpener should be the frame/iframe name.
        If not and it's only a normal window, you need to add this script to the opener page.

        window.name = "WindowNameOfOpener";

        This alternative solution will always open the desired page even if the opener page does not exist or has been closed or replaced by another page.
        Glenn
        vBulletin Mods That Rock!

        Comment


        • #5
          i dont see why there is no documentation of this issue online saying that that code is the only one to work on safari
          In fact the full correct reference should be

          window.element
          window.method

          Most of the window is ommited, as everything on page must have the base reference the window object, so that somehow the full reference looked like a pleonasm... It looks like Safari is a little bit scrupulous and need the full and precise reference, I guess
          KOR
          Offshore programming
          -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

          Comment

          Working...
          X