JavaScript open URL in a modal window | Example code

  • by

Use the window open() method to popup a window tab as a modal with a URL.

Note: JavaScript already has the ShowModalDialog function but it does not work in all browsers.

JavaScript open URL in a modal window Example

HTML example code:

<html>
<body>

	<script>

		var popUpObj;

		function showModalPopUp(){

			popUpObj=window.open("PopUp.htm","ModalPopUp","width=400," + "height=300");

			popUpObj.focus();

			LoadModalDiv();

		}

	</script>

	<input id="Button1" type="button" value="button" onclick="showModalPopUp()" />
</body>
</html>

Output:

JavaScript open URL in a modal window

More parameters can use in the window.open

You can freeze the parent window and when the popup is closed the parent window is changed back to normal.

window.open("PopUp.htm",
			"ModalPopUp",

			"toolbar=no," +

			"scrollbars=no," +

			"location=no," +

			"statusbar=no," +

			"menubar=no," +

			"resizable=0," +

			"width=400," +

			"height=300," +

			"left = 490," +

			"top=300"

);

Do comment if you have any doubts and suggestions on this JS URL tutorial.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.