[英]Set Focus to a popup window from C# (or JS)
我正在嘗試獲取一個彈出窗口以聚焦我嘗試過window.open().focus();
但它在后台不斷變化,因此我嘗試在我的代碼中關閉一個窗口,然后再次將其重新打開。
string url = "Report.aspx";
string s = "window.open('" + url + "', 'popup_window456789123', 'width=650,height=500,left=100,top=100,resizable=yes,scrollbars=yes')";
string t = "window.close()";
this.ClientScript.RegisterClientScriptBlock(this.GetType(), "Close", t, true);
ClientScript.RegisterStartupScript(this.GetType(), "script", s, true);
誰能告訴我為什么這行不通?
我在Jquery中嘗試了一下,但是還是沒有用:
<script type="text/javascript">
$(document).ready(function () {
alert("test");
window.focus();
});
</script>
流:
好的,我做了一個小提琴,顯示了您應該擁有的東西。 查看小提琴
如果我單擊一個窗口,然后單擊另一個窗口,則它將返回(重新加載)並獲得焦點。
如果您希望某個文本框成為焦點,或者在加載的窗口中出現某個東西,那么您需要在頁面中放置一些東西以使該文本框成為焦點。
<script> function openwin(url) {
window.open(url, 'popup_window456789123','width=650,height=500,left=100,top=100,resizable=yes,scrollbars=yes ')
}
</script>
<button onclick="openwin('https://www.webpagetest.org/')">
Button1
</button>
<button onclick="openwin('https://www.webpagetest.org/')">
Button2
</button>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.