Status
Not open for further replies.

Ashleyuk1984

Active Member
1,242
2010
304
1,020
Hope you can help me with this.

I have a 3rd party website that I want to show a snippet of on MY website using iframe. Simple right?

No.

It seems that this 3rd party website has a tiny piece of javascript:

Code:
<script type="text/javascript">     <!--         if (top.location != self.location)         { top.location = self.location.href }      //-->     </script>

When I load my page, it then starts to load the iframe, but because of the code that they have in their script, it totally hijacks my website, and redirects to their URL.

Is there a way to prevent this? and just keep the 3rd party website inside the iframe?

Thanks
 
2 comments
i think you wanna place ifames for url shortening sites in your website or something similar

basically this line here

<script type="text/javascript"> <!-- if (top.location != self.location) { top.location = self.location.href } //--> </script>

means that the website can not be loaded within frame, if you do it will redirect to the url of the iframe you included

so this can not be done, cuz you can not modify javascript of 3rd party website so do not waste your time
 
Well! You can try out to actually modify the iframe source before it is shown to user. Just wrote a sample code which does the work:

PHP:
<html>
<head><title>Test</title></head>
<body>
<script type="text/javascript">
function Removejsfromifram(frameid) {
    var capturediframe = document.getElementById(frameid);
    capturediframe.contentWindow.document.body.innerHTML = capturediframe.contentWindow.document.body.innerHTML.replace('<script.*?type="text/javascript".*?>.*?<\/script>', '');
    // Remove Javascript from Iframe using javascript - Soft2050
}

</script>
<body>
<iframe id="softid" src="test - Copy.html" onload="Removejsfromifram('softid')" ></iframe>
</body>
</html>

It will remove all javascript code from the source so no hijacking.
 
Status
Not open for further replies.
Back
Top