如何在同一iframe中打开第二个链接

时间:2017-11-30 19:05:30

标签: javascript iframe

我有这段代码:

<script>
function releu1On() {
 var url = 'http://10.10.5.155/30000/01';
 var elem = document.createElement('a');
 setTimeout(function(){window.location.href="http://10.10.5.155/30000/00"} , 1000);
 elem.href = url;
 elem.target = 'hiddenIframe';
 elem.click();
}
</script>

<iframe style="display:none;" name="hiddenIframe" id="hiddenIframe"></iframe>
<button type="button" class="btn btn-success" onclick="releu1On()"/>1. On</button>

我想要第二个链接,从setTimeout条件在相同的iframe之后打开一定数秒,而不在页面中跟随/加载。我希望它被隐藏起来。

2 个答案:

答案 0 :(得分:0)

我修改了你的方法,见下文:

   function releu1On() {

    var firstLink = document.createElement("a");

    firstLink.setAttribute("type", "hidden");

    firstLink.setAttribute("name", "name_you_want");

    firstLink.setAttribute("href", "http://10.10.5.155/30000/01");

      $('#hiddenIframe').contents().find('body').append(firstLink);

    setTimeout(function(){    

        var secondLink = document.createElement("a");

          secondLink.setAttribute("type", "hidden");

          secondLink.setAttribute("name", "name_you_want");

          secondLink.setAttribute("href", "http://10.10.5.155/30000/00");

          $('#hiddenIframe').contents().find('body').append(secondLink);

  } , 1000);

}

答案 1 :(得分:0)

我成功完成了以下代码:

function releu1On() {
 var url = 'http://10.10.5.155/30000/01';
 var elem = document.createElement('a');
 setTimeout("document.getElementById('hiddenIframe').src = 'http://10.10.5.155/30000/00';",2000);
 elem.href = url;
 elem.target = 'hiddenIframe';
 elem.click();
}