Link to home
Start Free TrialLog in
Avatar of hypervisor
hypervisor

asked on

Always open in new window when using javascript to create a pop-up

I am using the following function to create a pop-up window:

function popitpat(url)
{
        newwindow=window.open(url,'name','height=450,width=1000,scrollbars=yes');
        if (window.focus) {newwindow.focus()}
        return false;

Open in new window


The function works great, however if the user clicks the link multiple times the link re-opens in the window it created originally.  I would like a new pop-up to be created each time the link is clicked.  Any help would be appriciated.
Avatar of Sudhindra A N
Sudhindra A N
Flag of India image

use this..

<script>
var wcounter = 1;
			function popitpat(url)
			{
				var wname = 'Name'+wcounter;
				wcounter++;
				newwindow=window.open(url,wname,'height=450,width=450,scrollbars=yes');
				if (Window.focus) {newwindow.focus(); }
				return false;
			}
</script>

Open in new window

if the user clicks the link multiple times
Are you saying that you want the url to be open in multiple popup windows if the user clicks the same link mulitple times? Or do you have several different links that you want each opened in a different popup window?

As it is, you are using the variable "newwindow" to reference the popup so each time the link is clicked, the window stored in the variable "newwindow" will be reused to open the link again. If you want multiple popups, you'll need to use multiple variables to reference them (newwindow1, newwindow2, etc.)
Avatar of hypervisor
hypervisor

ASKER

ansudhindra, the code you posted looks like what I need but I can't get it to work.  Thoughts?
ASKER CERTIFIED SOLUTION
Avatar of experts1
experts1

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,
Try adding target=_blank attribute!
newwindow=window.open(url,'name','target=_blank,height=450,width=1000,scrollbars=yes');

Open in new window


Hope it helps u...