How to open Modal window in Javascript

Posted on Jan 29, 2009 | 2 Comments

Sometimes we need to show Modal window in our web application. This window basically opens a popup window which does not allow the user to click any link in the background. User will be able to click on the background when he/she closes the window. The code snippet is given below:


  1. <html>
  2. <body>
  3. <script language=“JavaScript”> function openWindow()
  4. {
  5. var myArguments = ‘nothing’; window.showModalDialog(”http://www.google.com”, myArguments, ”);
  6. }
  7. </script>
  8. <button onclick=“openWindow();”>Click Here</button> </body>
  9. </html>

No related posts.

2 comments

  1. Badotz says:

    Is “window.showModalDialog” browser-neutral?

  2. admin says:

    The window.showModalDialog feature was not added to Firefox until version 3.0 https://developer.mozilla.org/en/DOM/window.showModalDialog

    so it won’t work if you use this javascript in old browser. I don’t have any idea if it works or not in Chrome? Any idea Badotz?

Leave a comment

Spam Protection by WP-SpamFree

Advertisement

Subscription

You can subscribe by e-mail to receive news updates and breaking stories.