Like said in the title, is there something like that? Reason asking was because sometime you get tired of other people iframing your site especially downloads site. Can anyone point me where I can find such code? Many thanks.
Use this: <script language="JavaScript"> <!-- if (self.location.href != top.location.href) { top.location.href = self.location.href; } // --> </script> Code (markup): BTW: I think this should belong to the JavaScript forum. But if you need this in PHP, I believe checking $_SERVER['HTTP_REFERER'] is the way.
Thanks. But can you share a code where when a page is being call by an iframe, it will show a custom page asking user to go to a link for that real page?BUT if the page is called by authentic user then it loads fine. Anyway to do this?
Here is some code using php that will work <?php $checkSite = $_SERVER['HTTP_REFERER']; $sitename="www.yoursite.com"; ?> <html> <body> <?php if (($checkSite == "")||($checkSite ==$sitename)) { ?> Welcome to my site your page code codes here!! <?php } else { ?> Please visit my site at www.yoursite.com <?php } ?> </body> </html>
This is what I meant by people freaking iframing my site. http://freerapid.org/linkgenerator/2 They iframed my site right from their site! I just want to have a code so that when people try to load my site in a frame, a message will show saying redirecting to the site and then it will redirect people straight to mine. Is it possible?
Just noticed the code..sorry, I missed that one. Implemented and it works. Now, I going to implement on all my sites. Thanks both of you.
Okay, this code works fine except that it detects my site using iframe too. Try go to "server files", tick one file and choose any "action" from the drop down menu. You'll see the message. Anyway to whitelist my own url?
Try: if (self.location.href != top.location.href && !top.location.hostname.match(/domain\.com/) { top.location.href = self.location.href; } Code (markup): If it doesn't work, it gives you an idea which you should expand upon..
It's pure javascript, it doesn't need to be combined with anything. Ofcourse you'll have to edit it to change domain\.com to your domain.. (without www, index.html etc) and \ before .
So, I can use it like this? <script type="text/javascript">if (self.location.href != top.location.href && !top.location.hostname.match(/rsmaker\.com/) { top.location.href = self.location.href; }</script> PHP: **Updated: script not working. Link clicked from my own site still showing the iframe message.
Since you PM'd me I'll show it to you.. I usually don't do this, please get a web development book and learn on your own, it will only help you with your online business.. Your page you're trying to protect should be like this: (assuming rsmaker.com is your site) <html> <head> <script type="text/javascript"> if (self.location.href != top.location.href && !top.location.hostname.match(/rsmaker\.com/)) { top.location.href = self.location.href; } </script> </head> <body> .. site content .. </body> </html> HTML:
[UPDATE] Code not working. 1- Try go to www.rsmaker.com and once the page load, click on the logo. It supposed to go to the site again, like refresh but instead it shows the iframe message. 2- Hmm...seems like any links on other sites pointing to my site was shown the message. Like the link I asked you to click above, it will show the same message. Going to remove the code for now until someone can tell me what did I do wrong. Thanks for those who helped, rep +. ========= Appreciate your help. Basically what I pmed you just now was correct. I've got myself some reference ebook from sitepoint. Still getting myself used to it though as I barely finished php. Thanks again.