Forum Moderators: open

Message Too Old, No Replies

Please help with script for iframe

How to make page opened only in iframe page with particular address....

         

vkartas

10:04 am on Jun 25, 2005 (gmt 0)

10+ Year Member



Hi everybody,
Can somebody help me to figure out what am I doing wrong

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

Moby_Dim

5:09 pm on Jun 25, 2005 (gmt 0)

10+ Year Member



May be use better : top.location.href = url

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 ;)

vkartas

9:01 am on Jun 26, 2005 (gmt 0)

10+ Year Member



Dear Moby_Dim
Thanks a lot. Your solution works perfect!

Moby_Dim

12:51 pm on Jun 26, 2005 (gmt 0)

10+ Year Member



Help yourself ;)

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...