

Html popup window code#

Html popup window windows#
If you want to see a working example of this code then check out the Pop-up Windows Examples Page.

Var linkElems = document.getElementsByTagName('a'),i Attach the onclick event to all your links that have the specified CSS class names Newwindow=window.open(popurl,popupName,eval(popupSpecs)) Opens the pop-up window according to the specified specs Var popupName = Math.floor(Math.random()*10000001) Create a "unique" name for the window using a random number figure out what popup size, etc to apply to the click When the link is clicked, this event handler function is triggered which creates the pop-up windows Set your 3 basic sizes and other options for the class names above - create more if needed initialize the 3 popup css class names - create more if needed Step 2: Add this javascript to the head or preferably to an external javascript fileĬlick on the code to select it all and then do your CTRL+C copy magic. You can use popup1, popup2, or popup3 for class names as in this html link code example below: Javascript Popup Step 1: Add the css class to any link that you want to act as a pop-up I've configured the code for 3 different size pop-ups but you can add more or change the existing ones easily. We will keep the html and the javascript separate which is a cleaner approach and in a practical sense will make things much easier for you to maintain going forward. We'll use a more modern approach and avoid putting the javascript code into the body of your HTML document. Also jQuery does a great job of reducing the cross-browser problems that often arise when using javascript.īut if you can't use jQuery to integrate the code for pop-up window functionality into your website then use the javascript code below. If you can, then use the jQuery popup code instead - it's lot more compact and sturdy. If you're in a hurry and quickly have to create a pop-up window for a single link then use the pop-up window generator.
Html popup window how to#
Create Pop-up Windows How to Use Javascript to Create Popup Windows Click here to show the popup × Add any HTML content inside the popup box! The CSS Code /* Popup box BEGIN */. The helper span is used to center the box vertically. This wraps the actual box with the close button.

Use the iframe below to test the live demo:Īdd a link that triggers the box and a div that behaves like the box shadow. The box and the shadow is hidden when the page loads, we have to trigger an event, like a link click to show it. We’re going to implement this using HTML, CSS and jQuery in less than 100 lines (not compressed code). In this article I’m going to walk you through the creation of a very simple popup box with shadow overlay and close button. Popup boxes are the most useful way of showing a warning or any other important information to the website visitors in many HTML5 templates.
