Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

new popup window on every click

Tags:

javascript

I've a pop up window which i'm opening using below script. On every click, i want to open new pop up. I understand, having unique name for the window will solve the problem (In this case "SampleWindow"). What's the best way to maintain the uniqueness of the window ? Is there any other way to manage javascript popup ?

window.open(url, 'SampleWindow', 'WIDTH=300,HEIGHT=250');
like image 974
Pankaj Avatar asked Feb 05 '13 19:02

Pankaj


People also ask

How do I get popups to open in a new window?

The syntax to open a popup is: window. open(url, name, params) : url. An URL to load into the new window.

How do you keep a pop-up window always on top?

To make the active window always on top, press Ctrl + Spacebar (or the keyboard shortcut you assigned).

What are pop-up windows?

A pop-up window is a window that appears on top of a help topic. The pop-up window sizes automatically to fit the amount of text or the size of the image in it. Pop-up windows remain on the screen until users click anywhere inside or outside of them.


1 Answers

Passing a value of _blank to the name parameter will load the passed URL into a new window. Like this:

window.open(url, '_blank', 'width=300,height=250');

Other options for name parameter (optional) include:

  • _blank - URL is loaded into a new window. This is default
  • _parent - URL is loaded into the parent frame
  • _self - URL replaces the current page
  • _top - URL replaces any framesets that may be loaded
  • name - The name of the window

Do note that if you'll be passing this JavaScript to an anchor tag A that IE browsers expect a return value, otherwise it'll referrence the A tag itself. Your code for that would look like:

<a href="javascript:var w=window.open(url, '_blank', 'width=300,height=250');">test</a>

or better (to avoid showing users your code in the status bar):

  <a href="javascript:void(0);" onclick="window.open(url, '_blank', 'width=300,height=250');">test</a>

Links:

  • window open() method reference
  • JSFiddle demo
like image 79
TildalWave Avatar answered Sep 19 '22 14:09

TildalWave