簡體   English   中英

JavaScript function 僅適用於 Internet Explorer(在 ASP.NET WebForms 中)

[英]JavaScript function works only in Internet Explorer (in ASP.NET WebForms)

在 aspx 頁面(WebForms)中,我有一個 JavaScript function 僅適用於 Internet Explorer 而不適用於 Edge/Chrome。

這個:

function ChoosePharmacy()
{ 
    var result = window.showModalDialog('search_pharmacy.aspx', window,"dialogWidth:800px;dialogHeight:600px;scroll: no;") 
    
    if (result != null)
            document.getElementById('hIdPharmacy').value = result;
}

這應該會打開一個彈出窗口 window(里面有一個 aspx 頁面),但是因為是一個舊的遺留應用程序,只能在 Internet Explorer 中工作,現在用戶已經轉移到 Edge,已經停止工作。

有人知道為什么嗎?

提前非常感謝。

路易斯

根據您的描述,我了解到您想知道為什么您的 JS 代碼無法在 Chrome 或 Edge 等現代瀏覽器上運行。

如果我們參考Window.showModalDialog()的文檔,我們會注意到它已被棄用,不建議在網站上使用。

在此處輸入圖像描述

正如 Elder 所建議的, 對話框是 window.showModalDialog() 的替代品。

如果很難在您的代碼中實現,那么作為替代方案,您可以使用ShowModalDialog Polyfill

您只需在代碼中添加對 ShowModalDialog Polyfill 的引用,您的代碼將開始工作而無需任何更改。

例子:

<!DOCTYPE html>
<html>
   <head>
      <title>Demo</title>
      <script src="https://unpkg.com/showmodaldialog"></script>
      <script>
         function ChoosePharmacy()
         { 
                    var result = window.showModalDialog('index.html', window,"dialogWidth:300px;dialogHeight:200px;scroll: no;") 
            
                    if (result != null)
                        document.getElementById('hIdPharmacy').value = result;
         }       
      </script>
   </head>
   <body>
      <h1>Example for ShowModalDialog Polyfill</h1>
      <br>
      <button onclick="ChoosePharmacy()">Call ChoosePharmacy Function</button>
   </body>
</html>

MS Edge 瀏覽器中的 Output:

在此處輸入圖像描述

暫無
暫無

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

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