在iframe中禁用onload函数的Javascript

Javascript to disable onload function inside an iframe

本文关键字:函数 Javascript onload iframe      更新时间:2023-09-26

我的网页上有一个iframe,源url是一个我无法访问的远程网页,问题是在iframe body onload事件中,有一个JS函数:

 <body onload="if(top!=self) top.location.href=location.href">

这样我的网页就会变成他们的网址。我是否可以在网页上使用javascript来禁用或重写该iframe中的body onload函数?我认为这与iframe加载事件不同。

尝试打破这种局面的唯一方法是使用服务器端代码(PHP、Ruby、Python等)将其页面代理到您控制的iframe中。您可以获取他们文档的来源并进行替换,以摆脱服务器端的onload事件。

你可能想建立一个类似于的结构

AppFolder
    index.html
    your_iframe.php

在您的iframe中,只需下载url的内容,然后进行替换并回显到浏览器。仍然有许多问题需要解决,例如iframed文档中的相对资源路径。