0

in aspx page (WebForms) I have a JavaScript function that works only in Internet Explorer and not in Edge/Chrome.

This one:

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

This should open a pop-up window (with an aspx page inside), but because is an old legacy application, works only in Internet Explore, and now that users have move to Edge, has stop working.

Do someone has idea why?

Thanks a lot in advance.

Luis

3
  • 1
    Edge does have an IE mode - so you should be fine Commented Sep 21, 2022 at 10:57
  • 1
    You can use native dialog Commented Sep 21, 2022 at 11:02
  • I cannot render IE native mode (browser settings are placed by Corporate), and how can I use dialog? In the link is not clear. Commented Sep 21, 2022 at 12:50

1 Answer 1

1

From your description, I understand that you would like to know why your JS code is not working with modern browsers like Chrome or Edge.

If we refer to the document for Window.showModalDialog(), we could notice that it is deprecated and is not recommended to use on the sites.

enter image description here

As suggested by Elder, dialog is a replacement for window.showModalDialog().

If it is difficult to implement in your code then as an alternative, you could use the ShowModalDialog Polyfill.

You just need to add a reference to ShowModalDialog Polyfill in your code and your code will start working without any changes.

Example:

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

Output in the MS Edge browser:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.