簡體   English   中英

將Focus設置為從C#(或JS)彈出的窗口

[英]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>

流:

  1. 主頁:單擊按鈕1►打開彈出窗口1
  2. 彈出窗口處於焦點並顯示數據
  3. 主頁(獲取焦點):單擊按鈕2►打開相同的彈出窗口1
  4. 彈出窗口更改數據(但沒有獲得焦點) 這是問題

好的,我做了一個小提琴,顯示了您應該擁有的東西。 查看小提琴

如果我單擊一個窗口,然后單擊另一個窗口,則它將返回(重新加載)並獲得焦點。

如果您希望某個文本框成為焦點,或者在加載的窗口中出現某個東西,那么您需要在頁面中放置一些東西以使該文本框成為焦點。

      <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.

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