Determine if page is in an iFrame?

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?
 
S

Steve Easton

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
 
J

Jon Spivey

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

Mike Mueller

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?
 
T

Trevor L.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top