View Full Version : Redirection if inside iFrame
Resplendent
12-31-2002, 06:39 PM
hi, i'm new here =)
basically, i'm trying to script something that would boot you if you entered the page, but if you viewed that page inside an iframe, you'd be fine. Here's what i got, but it doesnt work =(
<script>
if (self.location.href!=top.location.href)
top.location.href="main.html"; // or whatever the url is...
alert('bah')
</script>
chrismiceli
12-31-2002, 08:13 PM
<script>
if (self.location.href!=top.location.href) {
top.location.href="main.html"; // or whatever the url is...
alert('bah')
}
</script>
try that. you might want to wait for the page to load before doing this, try a timeout
setTimeout("if (self.location.href!=top.location.href) { top.location.href="main.html"; alert('bah') }", 1000);
Resplendent
12-31-2002, 10:18 PM
why would i want the page to load? What'd happen?
Resplendent
12-31-2002, 10:26 PM
oh, okay, i tried using the timeout one, and it didnt work... or maybei didnt wait long enough?
Resplendent
01-01-2003, 03:39 PM
*bump* anyone?
Graeme Hackston
01-01-2003, 07:18 PM
Originally posted by chrismiceli
you might want to wait for the page to load before doing this
have you tried it?
onload = function() {
if (self.location.href!=top.location.href) {
top.location.href="main.html"; // or whatever the url is...
alert('bah')
}
}
Resplendent
01-01-2003, 09:24 PM
so i would put it after all my code? like at the very bottom of <body> ??
could you explain why that'd work? I'm not home right now, so =\
Graeme Hackston
01-01-2003, 09:57 PM
Try this, it would be your iframe page.
<html>
<head>
<title>Iframe</title>
<script type="text/javascript">
onload = function() {
if (self.location.href!=top.location.href) {
} else {
top.location.href="http://www.codingforums.com";
alert('bah')
}
}
</script>
</head>
<body>
</body>
</html>
Graeme Hackston
01-01-2003, 10:08 PM
Originally posted by Resplendent
Redirection if inside iFrame
but if you viewed that page inside an iframe, you'd be fine
I'm confused about what you want to do. Do you want to redirect if the page is opened by itself?
Resplendent
01-01-2003, 11:45 PM
precisely
Resplendent
01-01-2003, 11:49 PM
ooooooooooh graeme thank you so much your code worked. Thanks alot again. Try going to systemdark.com =) and if u open the popup it works. But if u go to www.systemdark.com/news.htm it'll boot, thank you again =)
Graeme Hackston
01-02-2003, 12:21 AM
Your site looks good. This is cleaner and does the same thing.
<html>
<head>
<title>Iframe</title>
<script type="text/javascript">
onload = function() {
if (self.location.href==top.location.href) {
top.location.href="http://www.codingforums.com";
alert('bah')
}
}
</script>
</head>
<body>
</body>
</html>
Resplendent
01-02-2003, 12:39 AM
much thanks, shining person :thumbsup:
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.