如何使 IE 8 在 onload 元素完成之前不向 iFrame 显示任何内容?

发布于 2024-11-13 11:53:07 字数 979 浏览 4 评论 0原文

我想隐藏 iFrame 中加载的网站元素。脚本和站点可能需要一段时间,因此要求 iFrame 内容仅在修改后才显示。

我使用 onload 事件来执行隐藏元素的脚本。我可以访问 iFrame 内容(它位于同一域,但不在同一服务器/网络)。

function frameLoaded() {
sleep(3000); //simulating the time the script needs
var leftDiv = window.frames.testFrame.document.getElementById("leftcol");
leftDiv.style.display = "none";
}

简单的睡眠功能:

function sleep(milliSeconds){
var startTime = new Date().getTime(); // get the current time
while (new Date().getTime() < startTime + milliSeconds); // hog cpu
}

当第一次加载带有 iFrame 的网站时,会显示滚动条和一些样式元素,但没有内容文本:

http://img651.imageshack.us/img651/5082/beforeu.png

脚本完成后,页面将按其应有的样子显示(天蓝色div 变为隐藏):

http://img51.imageshack.us/img51/6806/afterq。 png

当脚本运行时,不应显示任何内容。一个空的 iframe 或整个网站等待加载完成就足够了。

I want to hide elements of an website loaded in an iFrame. The script and the site can take a while so it is requested that the iFrame content is only shown after it has been modified.

I use an onload event to execute the script which hides the elements. I have access to the iFrame content (it's on the same domain, but not the same server / network).

function frameLoaded() {
sleep(3000); //simulating the time the script needs
var leftDiv = window.frames.testFrame.document.getElementById("leftcol");
leftDiv.style.display = "none";
}

The simple sleep function:

function sleep(milliSeconds){
var startTime = new Date().getTime(); // get the current time
while (new Date().getTime() < startTime + milliSeconds); // hog cpu
}

When the Website with the iFrame is loaded for the first time a scroll-bar and some styled elements are shown, but no content text:

http://img651.imageshack.us/img651/5082/beforeu.png

When the script is done the page is displayed as it should be (the azure colored div becomes hidden):

http://img51.imageshack.us/img51/6806/afterq.png

While the script is working there shouldn't be displayed anything. Either an empty iframe or the whole website waiting till the onload is finished would be sufficient.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寂寞陪衬 2024-11-20 11:53:07

您可以在父页面加载和 iframe 集的 onload 事件上隐藏 这个可见:

function frameLoaded() {
  sleep(3000); //simulating the time the script needs
  var leftDiv = window.frames.testFrame.document.getElementById("leftcol");
  leftDiv.style.display = "none";
  document.getElementById("iframe").style.display = 'block';
}

顺便说一句:这个睡眠功能应该被扔掉。

You could have the <iframe id="iframe" style="display: none"> hidden on your parent page load and on the onload event of the iframe set this one to visible:

function frameLoaded() {
  sleep(3000); //simulating the time the script needs
  var leftDiv = window.frames.testFrame.document.getElementById("leftcol");
  leftDiv.style.display = "none";
  document.getElementById("iframe").style.display = 'block';
}

BTW: This sleep function should be thrown away.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文