Wrox Programmer Forums
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 20th, 2011, 03:26 PM
Registered User
 
Join Date: Mar 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Detect iframe

Hi
I really don't know where to post this question but I believe is related to JavaScript (Prove me wrong)

Question:
Let say my website is www.site.com. another website (www.example.com) uses iframe tag to load my website in their iframe using src="www.site.com"

Now, how can I detect from www.site.com that www.example.com trying to load my website from iframe tag.

possibly javascript code can handle that or I need to modify the configuration of my web server which is apache.


Thanks
Mark
 
Old March 21st, 2011, 06:30 AM
Authorized User
 
Join Date: Jan 2011
Posts: 86
Thanks: 1
Thanked 12 Times in 12 Posts
Default

Hi,

the general idea would be to inspect the window.top.location and then either try to redirect this (often not possible because of cross-browser scripting security) or prevent it from displaying your site.

The following script is not mine, but from the blog of Pawal Sumata (http://www.suwala.eu/blog/2011/02/04...parent-window/) and should do the trick:
Code:
<script type="text/javascript" >
    if (window.top !== window.self) {
        document.write = "";
        window.top.location = window.self.location; 
		setTimeout(function(){
            document.body.innerHTML='';
        },1);
        window.self.onload=function(evt){
            document.body.innerHTML='';
        };
    }
</script>
Hope this helps
 
Old March 22nd, 2011, 07:58 PM
Registered User
 
Join Date: Mar 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That makes sense.

Thanks for the help


--
Mark





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to get out from Iframe k.manisha ASP.NET 2.0 Professional 1 September 12th, 2007 12:20 PM
values from one iframe to another iframe URGENT raaj Beginning PHP 2 February 27th, 2007 12:19 PM
iframe help splinterz HTML Code Clinic 12 April 13th, 2005 01:42 AM
iframe rockon HTML Code Clinic 1 March 2nd, 2005 06:00 AM
iframe...or a better way? stacy HTML Code Clinic 4 September 4th, 2004 11:04 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.