簡體   English   中英

javascript:window.location.href / window.open無法使用iframe

[英]javascript : window.location.href/window.open is not working on iframe

更新的代碼

<div>
    <button type="button" class="submit btn btn-default" id="btnSubmit">Submit 
    </button>
    <button type="button">Cancel</button>
</div>




<script>
$("#btnSubmit").click(function(e)
 {
  e.preventDefault();

  //btn Click validation and code submission goes here..

   alert("Form has been successfully submitted");
   window.open("http://....../viewmyrequest.aspx","_self"); 

  }

</script>

window.location.href僅在調試模式下工作,如果我關閉調試模式,則不會重定向到其他窗口。

我已經使用相同的主題探索了許多StackOverflow問題,但我對此問題沒有得到任何可靠的回應。

window.location.href = "http://testwebsite.com/viewtickets.aspx"

我也嘗試過其他選擇

window.location = "http://testwebsite.com/viewtickets.aspx"
window.location.replace = "http://testwebsite.com/viewtickets.aspx"

嘗試這個。 在我的所有網站中跨瀏覽器工作。

loc = "http://testwebsite.com/viewtickets.aspx";
    window.open(loc,'_self');

編輯:這可能對你有用..

<script>
function setURL(url){
    document.getElementById('iframe').src = url;
}
</script>
<iframe id="iframe" src="idreesinc.com/research.html" />
<input type="button" onclick="setURL('URLHere')" />

它會將正確的URL插入iframe。

我99%肯定問題是你正在使用提交按鈕,並且提交的表單不允許你的JavaScript運行。 因此,您需要將類型設置為按鈕而不是提交按鈕,或者您需要取消單擊操作。

<button type="button" ... >

要么

<button onclick="foo(); return false;" ... >

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM