access the url of the iframe/frame/frameset from its src

CPSRI
CPSRI used Ask the Experts™
on
Hi,
I want to prevent un-authorized forwards to my domain, i noticed that some people are redirecting their websites to my website using frame/iframe/frameset. How can I prevent that? I can program in asp.net, asp..any ideas..

Thanks in advance.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2011

Commented:
Use frame-busting code similar to this:

if(top != self)
   {  
      window.open(location.href, '_top');  
   }

The use of  _top as the target parameter for window.open() will launch it in the same window.

There are other ways to do this but this is the easiest to me.
Top Expert 2013

Commented:
I you are just trying to prevent the pages from being framed then just add this script to the pages being framed.

<script language="Javascript">
<!--
if (top.location != self.location) {
top.location = self.location.href
}

//-->
</script>

Cd&
Top Expert 2013
Commented:
If you do not want them coming to your site at all, then change it to

<script language="Javascript">
<!--
if (top.location != self.location) {
top.location.href = 'http://www.someothersite.com';
}

//-->
</script>

Author

Commented:
THank you so much..

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial