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.
VPNJavaScript

Avatar of undefined
Last Comment
Roopesh Reddy

8/22/2022 - Mon
Sudhindra A N

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

Kim Walker

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.)
hypervisor

ASKER
ansudhindra, the code you posted looks like what I need but I can't get it to work.  Thoughts?
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER CERTIFIED SOLUTION
experts1

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Roopesh Reddy

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