Change the window name in your two different calls:
function popitup(url,windowName) {
newwindow=window.open(url,windowName,'height=200,width=150');
if (window.focus) {newwindow.focus()}
return false;
}
windowName must be unique when you open a new window with same url otherwise the same window will be refreshed.
Answer from Umesh on Stack OverflowChange the window name in your two different calls:
function popitup(url,windowName) {
newwindow=window.open(url,windowName,'height=200,width=150');
if (window.focus) {newwindow.focus()}
return false;
}
windowName must be unique when you open a new window with same url otherwise the same window will be refreshed.
To create a popup you'll need the following script:
<script language="javascript" type="text/javascript">
function popitup(url) {
newwindow=window.open(url,'name','height=200,width=150');
if (window.focus) {newwindow.focus()}
return false;
}
</script>
Then, you link to it by:
<a href="popupex.html" onclick="return popitup('popupex.html')">Link to popup</a>
If you want you can call the function directly from document.ready also. Or maybe from another function.
Best practices for opening new window (pop up or pop under) with JavaScript
Call pop up window always on top
Standardize a popup's condition and UI opened by window.open
Force popup windows to open in new tab?
Videos
Here at work, we do a fair bit of surveys on various sites via Survey Monkey. The MO has always been to do a pop under window - focus the parent, not the child/new window. I've stressed how I think this is slimey (hiding the new window), but it is what it is and that's that :)
Seems every time we have a survey, I'll get people coming to me because the new window is getting blocked by someone. I've looked at the code they're using and it's using the typical window.onload event. I tell them this is probably why they're getting blocked as the pop up blockers are no doubt seeing automatically opened windows as unwanted advertising. Because the window onload and onunload events have been so abused, this is why we have pop up blockers built into browsers as well as plugins.
I thought about perhaps using a timer to delay execution of the pop up from onload, but not sure if this will make any difference. I'm kind of guessing not but I haven't tested it yet. I can't really test it as it's another dept. that has access to the server, not me... I've also thought about using onmousemove to trigger it (user-triggered event) and then nulling that out but that seems even more stupid.
I've suggested adding static survey promos which would be user-triggered events as I think those might fare better in the world of pop up blockers - even though there's still no guarantee. So the user clicks to pop the new window.
I've also suggested removing JS from the equation altogether and having the promos link straight to Survey Monkey. The counter there is that they've lost where they are in our site (they could have deep-linked in). They can't just easily close the Survey Monkey window to pick back up where they left off in their task. Off the top of my head, I don't know if they can use their back button to backtrack from the end of the Survey Monkey survey, either.
Is there a general consensus of best practices in regards to opening a new pop up (or pop under) window with JavaScript with pop up blockers?
Ideally, the feature you are looking for in Edge to open a new tab is currently not available
LOLWUT
A popular feature which was a common, top-level setting in IE, and which has existed in both Chrome and Firefox for many years, was intentionally not imported into Edge's feature set? Who made that decision? This is why people continue to use non-MS browsers in the majority.
C'mon Microsoft, free tip from a Systems Engineer: don't remove/drop features that are very popular with users. This is requirements capture 101.
Thanks Aditya, we almost have this solved.
Holding the Ctrl key and clicking works exactly how I want it to EXCEPT I don't want to have to hold the Ctrl key, I want that action to be the default when I click on links that would otherwise open as a popup window. How do I do that?
Here's how it's done in Firefox:
"In order to force popups opening in a new tab instead enterabout:config into the firefox address bar (confirm the info message in case it shows up) & search for the preference named browser.link.open_newwindow.restriction. double-click it and change its value to 0**."
Is there anything like that for Edge?