[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How do I detect whether the document is in a frame or in an iframe?

Posted on 2005-04-19
5
Medium Priority
?
290 Views
Last Modified: 2008-03-03
thanks
0
Comment
Question by:zhghl
5 Comments
 
LVL 22

Assisted Solution

by:RedKelvin
RedKelvin earned 60 total points
ID: 13821479
this will tell you if the document is in a frame
http://www.irt.org/script/293.htm
0
 
LVL 6

Assisted Solution

by:Samer Chidiac
Samer Chidiac earned 60 total points
ID: 13822019
i'm not sure how you're going to use the information once you knew it ..

can you clarify why you want to know it...  ( like r you going to write a script to detect that and write an action to redirect users or something ? )

usually the framed page is a page that is formed from different pages assembled in together using frames, and the Main Framed Page is very simple can cannot include but frames (it even don't have a <Body> Tag) while the sub pages contains the Content .. while an iframe can be embedded in a normal page.. and can be floating..

Take Care,

SC

------------
Samer Chidiac
Microsoft MVP - ASP / ASP.net
0
 
LVL 2

Assisted Solution

by:terminator_III
terminator_III earned 60 total points
ID: 13822192
Hi you can add this into the <body> tag of any page and it will take you to the correct page.  You can change the url of course.  This is fix is needed if a search engine arrives at a parentless page and you want to put the navigation back.

Look at the parent.frames.length aspect

<body topmargin="0" leftmargin="0" OnLoad="if(parent.frames.length==0)top.location='http://www.visicomscientific.co.uk';">

Shout if you need more help on what to do after you redirect.

rgds
Scot
TIII
0
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 120 total points
ID: 13823148
in the head of the page
<script type="text/javascript">
function testSelf()
{
   arr=top.document.getElementsByTagName('frameset');
   return (arr.length==0) ? 'iframe' : 'frame';
  </script>

In the body tag of the framed page you fire it with:

<body onload="if (self != top) alert(testSelf());"

Cd&
0
 

Author Comment

by:zhghl
ID: 13830616
if( top != self ){
     if( window.frameElement.tagName== "IFRAME" ){
      alert( "iframe" );      
    }else{
      alert( "frame" );      
    }
}else{
   alert( "page" );
}

thanks a lot
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses
Course of the Month20 days, 12 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question