4 Replies - 2522 Views - Last Post: 28 September 2009 - 01:37 AM

#1 devitk_90  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 05-September 09

child window location value

Post icon  Posted 26 September 2009 - 08:34 PM

I am doing my final year project. I am trying to access webpages via javascript. while i am doing this i open a new window to display webpages.And i have to get the url from child window while i am navigating the webpages. I have tried to get the url from child window after the new window is opened. But i get the null value as a result. Please refer me soon.


<html>
<head>
<script language="javascript">
var a="null";
function f1()
{
project = window.open("http://www.google.com","project","location=no,status=no,scrollbars=no,resizable=no,toolbars=no");
window.focus();
a=project.location.href;
}
function f2()
{
alert(a);
project.close();
}

</script>
</head>
<body>
<form name="f">
<input type="button" value="open" onclick="f1();">
<input type="button" value="close" onclick="f2();">
</form>
</body>
</html>




Is This A Good Question/Topic? 0
  • +

Replies To: child window location value

#2 musya  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 11
  • View blog
  • Posts: 1,012
  • Joined: 25-April 07

Re: child window location value

Posted 26 September 2009 - 10:20 PM

If you know the URL your opening up why are you trying to retrieve that very url then? I guess I'm just a bit confused as to what you are trying to achieve?
Was This Post Helpful? 1
  • +
  • -

#3 devitk_90  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 05-September 09

Re: child window location value

Posted 27 September 2009 - 11:36 AM

As you see in my code i am trying to open the window that shows google home page. If suppose i try to navigate through link in the google home page then the new webpage is displayed. This webpage may be from different server that is loaded in the same window. At that time how can i find out the url of the current page loaded.
Was This Post Helpful? 0
  • +
  • -

#4 musya  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 11
  • View blog
  • Posts: 1,012
  • Joined: 25-April 07

Re: child window location value

Posted 27 September 2009 - 12:04 PM

Okay I think I got this now,

Change your lines from:
window.focus();
a=project.location.href;



To:
project.window.focus();
a=project.opener.location.href;


you needed project in the focus line so it knows what windows to focus I guess, but the important part was the opener part. Not sure why or what it does but that should work, It worked on my computer. Now I'm not sure if it gets the variables passed through or not but hopefully its a starting place for you.
Was This Post Helpful? 1
  • +
  • -

#5 devitk_90  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 05-September 09

Re: child window location value

Posted 28 September 2009 - 01:37 AM

As you suggest me i tried out your code. But i got the parent window url. But i want Child window url in parent window whenever the child window loads a new page.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1