• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 526
  • Last Modified:

remove frame and iframe??

using javascript can anyone please help to make the page come out of IFRAME.
i have the code to come out of the Frame but not from IFRame.

can you please help.

code below helps to come out of frame but not iframe
<SCRIPT LANGUAGE="JavaScript">
<!--
setTimeout ("changePage()", 3000);
function changePage() {
if (self.parent.frames.length != 0)
self.parent.location="default.aspx";
}
// -->
</SCRIPT>
0
swech
Asked:
swech
3 Solutions
 
JakobACommented:
<SCRIPT LANGUAGE="JavaScript">
<!--
setTimeout ("changePage()", 3000);
function changePage() {
    if ( top != self ) {   // should work for frames and iframes both.
        top.location="default.aspx";
    }
}
// -->
</script>

regards JakobA
0
 
devicCommented:
<script>
if (top.location != self.location)
{
      top.location = self.location.href
}
</script>
0
 
ZontarCommented:
if(top != self)
  top.location.href = self.location.href;

location is an *object*; its href property is the URL string. Setting location doesn't work in some browsers -- set location.href instead.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
JakobACommented:
>> swech
  Zontar is right. I should have made that correction.
0
 
NetGrooveCommented:
Here my proposal:

<SCRIPT LANGUAGE="JavaScript">
<!--
setTimeout ("changePage()", 3000);
function changePage() {
  if (top.frames.length != 0)
     top.location="default.aspx";
}
// -->
</SCRIPT>

The reason for my variant is that parent can be written when not same domain, but can not be read for the compare.

Good luck,
NetGroove

0
 
anstpCommented:
here's how i would do it similar to zontar
<script>
if (top.location != self.location)
{
self.location.url="default.aspx"    
top.location = self.location.url
}
</script>
0
 
swechAuthor Commented:
Thanks for the  answer.
sorry zontor could not accept you answer coz i'm totally new to javascript so had to do some research on how to redirect to default.aspx. But thanks to anstp for the correct answer.
jokoba's code also worked .

working fine now.,

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now