Trouble retrieving window location from a previously opened window ?

Discussion in 'Javascript' started by Mark, Dec 24, 2005.

  1. Mark

    Mark Guest

    Hi,

    I am trying to open up a new window and then get the current url/location
    back from the (win_1) window and display the url in an alert box.


    Here is the code I am using :-

    <script type="text/javascript">
    var mywin_1 = open ("http://www.anysite.com/index.htm", "win_1",
    "height=640, width=820, left=200, top=0, scrollbars, status, location");
    var temp = mywin_1.location;
    alert (temp);
    </script>


    Where am I going wrong?


    Thanks in advance, Mark
    Mark, Dec 24, 2005
    #1
    1. Advertising

  2. Mark

    Lee Guest

    Mark said:
    >
    >Hi,
    >
    >I am trying to open up a new window and then get the current url/location
    >back from the (win_1) window and display the url in an alert box.
    >
    >
    >Here is the code I am using :-
    >
    > <script type="text/javascript">
    > var mywin_1 = open ("http://www.anysite.com/index.htm", "win_1",
    >"height=640, width=820, left=200, top=0, scrollbars, status, location");
    > var temp = mywin_1.location;
    > alert (temp);
    > </script>
    >
    >
    >Where am I going wrong?


    1. You should specify window.open(), because there is also a document.open()
    method. That's not causing you any problems, though.

    2. As written, I see the alert: "about:blank" in Firefox, because you're
    trying to read the location too soon after the window.open() call.
    The browser hasn't even had time to contact the "www.anysite.com",
    server, let alone load the new page.

    3. You should be alerting the value of location.href, rather than location,
    if only because the resulting error message is easier to understand.

    4. If you do add a delay, and you do alert the value of location.href, you
    will see an error message telling you that you don't have permission
    to read the location of a window open on a site that differs from the
    site that served the current page. It's a security feature to prevent
    people from popping up new windows and then keeping track of where the
    user navigates in that window.
    Lee, Dec 24, 2005
    #2
    1. Advertising

  3. Mark

    Mark Guest

    "Lee" <> wrote in message
    news:...
    > Mark said:
    >>
    >>Hi,
    >>
    >>I am trying to open up a new window and then get the current url/location
    >>back from the (win_1) window and display the url in an alert box.
    >>
    >>
    >>Here is the code I am using :-
    >>
    >> <script type="text/javascript">
    >> var mywin_1 = open ("http://www.anysite.com/index.htm", "win_1",
    >>"height=640, width=820, left=200, top=0, scrollbars, status, location");
    >> var temp = mywin_1.location;
    >> alert (temp);
    >> </script>
    >>
    >>
    >>Where am I going wrong?

    >


    > 4. If you do add a delay, and you do alert the value of location.href, you
    > will see an error message telling you that you don't have permission
    > to read the location of a window open on a site that differs from the
    > site that served the current page. It's a security feature to prevent
    > people from popping up new windows and then keeping track of where the
    > user navigates in that window.
    >


    Hi,

    Thanks for your help on items 1 - 3.

    The problem I was having (using Internet Explorer) was that it didnt
    acutally display any alert at all (though did say access denied if I
    double-click on the '!' on the status bar) obviously I now understand why.


    Item #4 - I can understand about the security prevention, but I thought I
    would be able to get around this with myself opening the window originally.
    There must be some way to get the URL of an open window which the code is
    not running in ? Any advice?

    The web page in question is for use internally on a standalone machine so I
    can lower any 'restrictions' in the actual browser if this needs to be ?



    Thanks, Mark
    Mark, Dec 24, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Daniel Walzenbach
    Replies:
    6
    Views:
    3,732
    Daniel Walzenbach
    Nov 18, 2003
  2. raj
    Replies:
    8
    Views:
    530
    J. Baute
    Apr 9, 2004
  3. Manjit
    Replies:
    0
    Views:
    206
    Manjit
    Jul 25, 2003
  4. datactrl
    Replies:
    3
    Views:
    127
    Thomas 'PointedEars' Lahn
    May 29, 2004
  5. sowen
    Replies:
    2
    Views:
    158
    Thomas 'PointedEars' Lahn
    Aug 8, 2007
Loading...

Share This Page