【问题标题】:How can I open an iframe automatically?如何自动打开 iframe?
【发布时间】:2012-11-21 19:26:31
【问题描述】:

我有两个 iframe,iframe1 和 iframe2。 iframe1 有 4 个链接。现在,当我单击最后一个链接时,我已经能够关闭 iframe。但是在关闭它时,我希望在没有任何用户启动操作的情况下打开 iframe2。我怎样才能做到这一点?

这是我用来关闭 iframe1 的代码,然后我尝试像这样调用 iframe2:

编辑:

function prepareFrame() {
alert("Inside prepare frame");
ifrm = document.createElement("IFRAME");
ifrm.setAttribute("src", "openThis.jsp");
ifrm.style.width = 640+"px";
ifrm.style.height = 480+"px";
document.body.appendChild(ifrm);
}

function closeMyIframe() {
  var parentDynamicDiv = window.parent.document.getElementById('dynamic_id1');
  var iframe = window.parent.document.getElementById('dynamic_id2');
  iframe.style.display = 'none';
  parentDynamicDiv.style.display = 'none';
  prepareFrame();
}

prepareFrame() 中的警报即将出现,但模式未出现。

Iframe1 来自一个名为 myJSP.jsp 的父 jsp,因此当关闭时,我认为控件返回到该 jsp。从那里开始,我怎样才能自动打开新的 iframe?

请帮忙。

【问题讨论】:

  • 你的问题有点意思。 iframe2 是什么?您在代码 sn-p 中没有提到它。 iframe2 是否已经存在?为什么不最初隐藏它并在您的函数中将其显示更改为“阻止”?
  • 嗨,阿明,编辑了这个问题。
  • 顺便说一句,我正在使用 prepareframe() 中的代码构建 iframe2

标签: javascript jquery jsp


【解决方案1】:

假设您的 iframe1 id 是 dynamic_id1,iframe2 id 是 dynamic_id2,而您的函数 closeMyIframe() 在 iframe1 页面内。

如果是这样,只需更改您的代码行 4,从

iframe.style.display = 'none';

iframe.style.display = 'block';

【讨论】:

    猜你喜欢
    • 2012-06-27
    • 2012-06-07
    • 2022-10-02
    • 2012-02-11
    • 1970-01-01
    • 2022-10-05
    • 2013-07-22
    • 2017-02-18
    • 1970-01-01
    相关资源
    最近更新 更多