4 Replies - 466 Views - Last Post: 12 July 2012 - 07:47 AM

#1 Gary_Leeds  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 08-July 12

Is it possible to get the URL of a window opened with window.open?

Posted 11 July 2012 - 12:17 PM

As the topic says is it possible to read back the URL of a window/tab that is opened with window.open?

I have a lot of shortened URLs using sites like tinyurl etc but I would prefer to work directly with the full address.

I have written the following which according to information I found on google should work but it is returning the URL of the window that ran the code not the new one

myWindow = window.open(\'http://tinyurl.com/79anjy9\',\'_blank\');
sleep(10); // actually a php command but there to give time to get the correct url displayed 
document.write(window.location)); 
mywindow.close();



Is it possible to do?

Thanks
Gary

Is This A Good Question/Topic? 0
  • +

Replies To: Is it possible to get the URL of a window opened with window.open?

#2 ThrowsException  Icon User is offline

  • D.I.C Head

Reputation: 33
  • View blog
  • Posts: 83
  • Joined: 21-February 12

Re: Is it possible to get the URL of a window opened with window.open?

Posted 11 July 2012 - 12:38 PM

I don't have a server running right now to test this but by looking at your code you are assigning the window.open() function to myWindow but then you are using window.location in the document.write function try this.

document.write(mywindow.location));



Update: I ran this on my server using this code

var my_window = window.open('http://www.google.com'); 
setTimeout(function(){document.write(my_window.location);},1000);



and this is the error I receive from google developer tools
"Unsafe Javascript attept to access frame with URL https://www.google.com from frame within http://localhost/ Domains, protocols and ports must match.

This post has been edited by ThrowsException: 11 July 2012 - 12:49 PM

Was This Post Helpful? 1
  • +
  • -

#3 Gary_Leeds  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 08-July 12

Re: Is it possible to get the URL of a window opened with window.open?

Posted 11 July 2012 - 12:43 PM

I tried that and it leaves the window open and displays nothing, almost as if the code has failed and stopped due to an error
Was This Post Helpful? 0
  • +
  • -

#4 Gary_Leeds  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 08-July 12

Re: Is it possible to get the URL of a window opened with window.open?

Posted 11 July 2012 - 01:33 PM

View PostThrowsException, on 11 July 2012 - 12:38 PM, said:

I don't have a server running right now to test this but by looking at your code you are assigning the window.open() function to myWindow but then you are using window.location in the document.write function try this.

document.write(mywindow.location));



Update: I ran this on my server using this code

var my_window = window.open('http://www.google.com'); 
setTimeout(function(){document.write(my_window.location);},1000);



and this is the error I receive from google developer tools
"Unsafe Javascript attept to access frame with URL https://www.google.com from frame within http://localhost/ Domains, protocols and ports must match.


So no way of doing it automatically then :( Thanks for looking though

Does seem strange that something like a simple URL read is seen as a security loop hole though but must be there for a reason
Was This Post Helpful? 0
  • +
  • -

#5 ThrowsException  Icon User is offline

  • D.I.C Head

Reputation: 33
  • View blog
  • Posts: 83
  • Joined: 21-February 12

Re: Is it possible to get the URL of a window opened with window.open?

Posted 12 July 2012 - 07:47 AM

Most likely to prevent Cross Site Scripting. If you could start gaining access to other pages from yours by simply opening a window you could probably pull off some less than desirable things.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1