Determine if page is in an iFrame?

  • Thread starter Thread starter Victor
  • Start date Start date
V

Victor

Is there any way to test, using JavaScript, VBScript, ASP, or whatever, to
see if the web page displayed is being displayed in an iFrame?
 
Or right click in the middle of the page and see if the context menu has an option to "Open frame in
new window."

;-)


--
Steve Easton
Microsoft MVP FrontPage
95isalive
This site is best viewed............
........................with a computer
 
<script type="text/javascript">
if(this.location!=top.location)alert('You've been framed')
</script>
 
OK Victor, I'll answer your original question:
:::: Is there any way to test, using JavaScript,
VBScript,
:::: ASP, or whatever, to see if the web page
displayed is
:::: being displayed in an iFrame?


Yes you can do it. You would need to read the source in as
a string and then parse the string to look for the <iframe>
tag.




Victor wrote:
: Neither one answers my question. But then again, you
: wouldn't know that, would you?
:
:
:
: :: Or right click in the middle of the page and see if the
:: context menu has an option to "Open frame in new window."
::
:: ;-)
::
::
:: --
:: Steve Easton
:: Microsoft MVP FrontPage
:: 95isalive
:: This site is best viewed............
:: .......................with a computer
::
:: "clintonG"
:: message ::: View source.
:::
::: <%= Clinton Gallagher
::: METROmilwaukee (sm) "A Regional Information
::: Service" NET csgallagher AT metromilwaukee.com
::: URL http://metromilwaukee.com/
::: URL http://clintongallagher.metromilwaukee.com/
:::
:::
::: :::: Is there any way to test, using JavaScript, VBScript,
:::: ASP, or whatever, to see if the web page displayed is
:::: being displayed in an iFrame?
 
I tried this and got an error.

The code should read

<script type="text/javascript">
if(this.location!=top.location)alert('You\'ve been framed')
</script>

Without the escape character (\), the quote(') after "You" is read as the
end of the text for the alert and the rest is then read in as JS and fails

This also works:
<script type="text/javascript">
if(this.location!=top.location)alert("You've been framed")
</script>

--
Cheers,
Trevor L.
Website: http://tandcl.homemail.com.au

Jon said:
<script type="text/javascript">
if(this.location!=top.location)alert('You've been framed')
</script>


I choose Polesoft Lockspam to fight spam, and you?
http://www.polesoft.com/refer.html
 
Back
Top