How to Generate Popup Window in Javascript

Being a blogger, we always get hands with html coding in different instances. In this tutorial, I'll show you how to Generate Popup Window in Javascript to make a link open in a pop up window. Basically its about making Modal window or popup window also know as modal window using JavaScript. You can also make a popup link using HTML, but here we're showing the JavaScript technique. Its very simple if you try to understand the code.


Steps to Generate Popup Window in Javascript

To test your code, you can use our HTML editor.

  • Step1

Here's we're declaring the function and specify the hieght and width of the popup window. Just add the below code between <BODY> and </BODY> of your HTML Template.


<script type='text/javascript'>
var newwindow;
function popuplink(url)
if (window.focus) {newwindow.focus()}
</script> <!--TECHGYO POPUP CODE ENDS-->

The Popup link is the function name that we are going to use while placing the link to a text.

500 is the hieght of the popup window.
700 is the width of the popup window.

  • Step2

While adding hyper-link to a text use the function name Popup link and then the url as given below.

<a href="JavaScript:popwindow('ADD LINK HERE');">Open a popup window</a>

Try It: Click to here

popup link

You are done:) enjoy!!


  • You can use this JavaScript popup link for email subscription url.
  • Nobody will be able to copy the link by right-clicking.

Reference: Quackit : HTML Popup link Window Code


  1. Hello, sorry for my poor english...
    what if i want to open all links or external links in a popup window?
    thanks for your time

    • You need to find some scripts which does that function, you may find such scripts at, but its not recommended.

  2. Pop-up windows in many situation prove beneficial displaying some information but in many situation all those pop-up windows are restricted by Firefox. How to get through this problem ?

    • If the browser restricts any pop then you have to try ay alternative solutions like popunder or javascript notification etc.

Comments are closed.