Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detect Change In Frames URL

Status
Not open for further replies.

altendew

Programmer
Mar 29, 2005
154
0
0
US
Hi,

I current have a page with frames, the top frame is timer that counts down 10 seconds. The bottom page is a site. Once the top frame is done counting down from 10 seconds I want to see if the bottom page has changed (if the user has clicked). The bottom page is NOT part of my website.

Here is the code for the frameset.

Code:
<head>
<title></title>
<script language="javascript">
var startURL = "<?=$r['siteURL']?>";
function reLoad()
{
	window.opener.location.reload();
}
function getNew()
{

	if(window.location.href!=startURL)
	{
		return parent.contentPage.location.href;
	}
	else
	{
		return 0;
	}
}

</script>
</head>
<frameset rows="80,*">
	<frame name="banner" scrolling="no" noresize src="showTimer2.php?s=<?=$s?>&aid=<?=$aid?>">
	<frame name="contentPage" scrolling="yes" noresize src="<?=$r['siteURL']?>">
</frameset>
</html>

Here is the top frame. (showTimer2.php)

Code:
<html>
<head>
<title></title>
<link href="<?=$config['siteDir_url']?>style/style.css" rel="stylesheet" type="text/css">
<script>

function doLoad()
{
    setTimeout( "refresh()", <?=$special?>*1000 );
}

function refresh()
{
	alert(parent.getNew());
}

</script>
</head>
<body bgcolor="#000066" class="body" onload="doLoad()"'?>>

<table width="750" cellpadding="0" cellspacing="0" border="0" class="ptc">
	<tr>
		<td width="175" valign="top"><img src="<?=$config['siteDir_url']?>images/smallLogoNo.gif"></td>
		<td><?=$message?></td>
	</tr>
</table>

</body>
</html>

There is some PHP in here. As you can see what I tried to do. In the frameset I load the site URL into a javascript variable. Then in the top frame once the 10 seconds has counted I try to check and see if the URL has changed.

The only problem is I get a permission denied when executing "parent.contentPage.location.href" because it's not my domain. Do you have any ideas?
 
The error occurs for security reasons. AFAIK there is no way around it.

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Now, I'm doing this off of memory only, but if you simply want to get the URL of a specific frame in javascript, you should be able to do the following.
Code:
var startURL=parent.[i]frame_name[/i].location.href;
...

...where frame_name is the name of the frame you want to check.

 
Yes but that will only work if the frames website is in the same domain name.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top