The other answers are outdated. The behavior of Chrome for window.open depends on where it is called from. See also this topic.
When window.open is called from a handler that was triggered though a user action (e.g. onclick event), it will behave similar as <a target="_blank">, which by default opens in a new tab. However if window.open is called elsewhere, Chrome ignores other arguments and always opens a new window with a non-editable address bar.
This looks like some kind of security measure, although the rationale behind it is not completely clear.
Answer from Jeroen Ooms on Stack OverflowThe other answers are outdated. The behavior of Chrome for window.open depends on where it is called from. See also this topic.
When window.open is called from a handler that was triggered though a user action (e.g. onclick event), it will behave similar as <a target="_blank">, which by default opens in a new tab. However if window.open is called elsewhere, Chrome ignores other arguments and always opens a new window with a non-editable address bar.
This looks like some kind of security measure, although the rationale behind it is not completely clear.
This worked for me:
newwindow = window.open(url, "_blank", "resizable=yes, scrollbars=yes, titlebar=yes, width=800, height=900, top=10, left=10");
Videos
Per https://developer.mozilla.org/en-US/docs/Web/API/Window/open
It appears you need the second param.
window.open(url, windowName, [windowFeatures]);
openWindow(info) {
window.open('http://10.100.100.100:9999/window?someInfo=' + info, '_blank');
},
I was lodged here on search.
I faced such issue only on mobile chrome.
The two param didn't work for me. So i used 3 params.
openWindow(info) {
window.open('http://10.100.100.100:9999/window?someInfo=' + info, '_blank', 'popup=1');
}
or
openWindow(info) {
window.open('http://10.100.100.100:9999/window?someInfo=' + info, '_blank', '');
}
the parent window can only be accessed using the parent variable.
The following modification to opener1 function should make this possible
function opener1(){
try{
if(parent.window.opener != null && !parent.window.opener.closed)
{
parent.window.opener.test1();
}
}catch(e){ alert(e.description);}
}
Code seems to be fine for me. If you catch an exception you can log it to console to get information of what is wrong. Make sure domains of test1.html and test2.html match, otherwise you will get security exception.
Chrome extensions cannot use inline code. Instead, get the element in Javascript. See https://developer.chrome.com/extensions/contentSecurityPolicy
Please check this onClick within Chrome Extension not working
Chrome App Inline JavaScript will not be executed
I used to have this problem too, but I use Jquery, so far so good.
Try this:
window.open("","","width=400,height=150");
By the way chrome will block popup windows on page, until you give him access.
You need to pass _blank as another parameter:
From MDN:
To open a new window on every call of
window.open(), use the special value_blankforstrWindowName.
Example:
window.open('data:text/csv;charset=utf-8,'+escape(response), '_blank');
I am trying to create a temporary fix for this highly-annoying bug:
https://www.reddit.com/r/help/comments/13o7yif/why_does_reddit_open_image_links_in_their/
The solution to bust the proprietary image viewer is to open the image URL in a new tab and then close the current tab:
//Check to see if the image is being loaded in Reddit's proprietary image viewer. If the element exists, open the URL in a new tab and then close the current.
let elImg = document.querySelector("img.object-contain");
if (elImg) {
window.open(elImg.src,"_blank");
window.close();
}This works great when executed in the dev console directly, but Brave blocks it as a pop-up when it's executed by my Tampermonkey userscript. Is there a way to somehow trust the userscript source? Or perhaps there is another way to open a URL in a new tab without being blocked?
Update: While not an ideal solution, this does work:
let elImg = document.querySelector("img.object-contain");
if (elImg) {
elImg.addEventListener("click", function() {
window.open(this.src,"_blank");
window.close();
});
}It turns out that pop-ups are blocked when not executed by a user action. If I invoke the code by adding a click event to the element, it will work. However, I am still looking for a way to execute the code when the page loads.