Exoon Posted January 9, 2009 Share Posted January 9, 2009 Hello, I was wondering if its possible to check if the site has been loaded in an iframe and if it has then load it up to the full page automatically. As i have a script that is counting hits in from a website like a topsite and want to stop people cheating it. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
bubbasheeko Posted January 9, 2009 Share Posted January 9, 2009 I had found this somewhere and have modified it, wish I could credit the original source <script language="javascript"> // DO I FEEL AN IFRAME?? try { // Alright...what is the parent window url? var parent = window.parent.location; var str = new String(parent); } catch (e) //CHECKING - IF IT IS IN AN IFRAME SHOW ERROR PAGE { window.location = 'errorpage.html'; // CREATE AN ERROR PAGE AND PUT IT IN HERE } </script> <noscript>Your browser is not javascript enabled or it has been disabled. Javascript is required to see this page.</noscript> Hope this helps! Quote Link to comment Share on other sites More sharing options...
Exoon Posted January 9, 2009 Author Share Posted January 9, 2009 Hey, thanks for the reply. Do you know how i could use this to open the page to a full screen, because i still want the visitor on the website i just dont want anyone putting an iframe to 1x1 or somthing thanks Quote Link to comment Share on other sites More sharing options...
corbin Posted January 9, 2009 Share Posted January 9, 2009 You could try doing: window.parent.location = 'http://yoursite.com/'; Quote Link to comment Share on other sites More sharing options...
bubbasheeko Posted January 9, 2009 Share Posted January 9, 2009 That does not work - tested that today and the parent.document setting will affect the content of the iframe only. Strange behavior considering that same tag is used to check the url of the parent page. Quote Link to comment Share on other sites More sharing options...
bubbasheeko Posted January 10, 2009 Share Posted January 10, 2009 Here this will just simplify it if the visitors browser has javascript enabled: <script type="text/javascript"> if (top.frames.length!=0) { if (window.location.href.replace) top.location.replace(self.location.href); else top.location.href=self.document.href; } </script> <noscript>Your browser is not javascript enabled or it has been disabled. Javascript is required to see this page.</noscript> If a frame is detected it will remove it and place your site in the parent window. Quote Link to comment Share on other sites More sharing options...
Exoon Posted January 10, 2009 Author Share Posted January 10, 2009 thanks, thats working great!! Quote Link to comment Share on other sites More sharing options...
bubbasheeko Posted January 10, 2009 Share Posted January 10, 2009 Hey Exoon, Great! Just remember to mark the thread as resolved! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.