JavaScript open URL in a modal window | Example code

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

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

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

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