Forum Moderators: open
I have page with iframe 'http://www.mysite/index.htm'and iframe src 'http://www.mysite/test.htm'
Now I need test.htm to be opened ONLY from index.htm and be redirected to another page 'http://www.mysite/stop.htm'if someone will use it as a frame source for page with different address or will call it directly.
I tryed following approach
<script language="JavaScript" type="text/JavaScript">
<!--//
if(window.parent.frames.location.href!= 'http://www.mysite/index.htm'){self.parent.location='http://www.mysite/stop.htm';}
//-->
</script>
in different variations and it can handle orphaned test.htm but if I use test.htm as a source for another frame I do not get expected redirect.
Thanks in advance
next - review your logic : you check ONLY index page as parent, and 'if not' is true, you try to move to stop page. But loading in 'stop', your 'test' checks the condition again, and... Got this? So, check both : index and 'stop'.
wait, check not index.htm per se, but / too : if you use url as 'http://www.mysite.com/', you have DIFFERENT location.href
hence, try this :
<!--
var a = top.location.href;
if((a!= 'http://www.mysite.com/')&&(a!= 'http://www.mysite.com/index.htm')&&(a!= 'http://www.mysite.com/stop.htm')) {
top.location.href = 'http://www.mysite.com/stop.htm'
}
// -->
and welcome to WebmasterWorld ;)
I'd say - good enough but not perfect. The trouble is that i've decided to test this solution this morning (when i posted the reply, i did not do this), and found a problem : when you hit back button in Opera (mine is v.7.54), you return to the page with captured url or to the url itself (here - your 'test.htm') without any problem. Seems opera does not fire onload event when use history urls collection. (or just caching works, i do not know the details). Still do not know how to solve this :( Checking on timer seems too brute and vulgar...