It's a setting in chrome. You can't control how the browser interprets the target _blank.
It's a setting in chrome. You can't control how the browser interprets the target _blank.
"_blank" is not guaranteed to be a new tab or window. It's implemented differently per-browser.
You can, however, put anything into target. I usually just say "_tab", and every browser I know of just opens it in a new tab.
Be aware that it means it's a named target, so if you try to open 2 URLs, they will use the same tab.
try this
onclick="window.open('http://www.google.com', '_self');
well it is browser specific, i tested it on mozilla and is working fine, but on chrome it open in new browser window. You can suggest to chrome makers or call ajax synchronus.
use async:false will work.
NOTE: In IE, open new browser window is default behaviour. user need to set settings explicitly
This should do it:
var myWindow=window.open('');
myWindow.document.write("<div id='hello'>hey<div>");
var range = myWindow.document.createRange();
range.selectNode(myWindow.document.getElementById('hello'));
myWindow.getSelection().addRange(range);
myWindow.select();
var popup = window.open('message.html',"'" + name + "'",'height=300,width=300,location=no,resizable=yes,scrollbars=yes');
var element = document.createElement('div');
element.setAttribute('id', 'mydiv');
element.appendChild(document.createTextNode('blah blah'));
popup.window.onload = function() {
var win = popup.document.body;
win.appendChild(element);
var el = popup.window.document.getElementById('mydiv').innerHTML;
alert(el); //tested - ouputs 'blah blah'
};
While it's no longer possible to do this in Chrome, there are workarounds, such as opening a blank document and writing to it.
var win = window.open();
win.document.write("<img src='"+canvas.toDataURL()+"'/>");
That's because of a recent change in Chrome:
https://developers.google.com/web/updates/2017/03/chrome-58-deprecations#remove_content-initiated_top_frame_navigations_to_data_urls
You cannot open data URLs directly anymore this way for security reasons.
Instead use the workaround proposed by @Savoo here in the other answer or use a download anchor and click it via JavaScript.
As per Mozilla Developer docs first parameter of open() will be a url. If url is an empty string, then a new blank, empty window (URL about:blank) is created with the default toolbars of the main window. also URLs won't load immediately. When window.open() returns, the window always contains about:blank. The actual fetching of the URL is deferred and starts after the current script block finishes executing. The window creation and the loading of the referenced resource are done asynchronously.
It can not be removed but you can change the text "about: blank" to your current URL by putting space in first position or by giving specific path.
var win = window.open(
"http://www.domainname.ext/path.png",
"DescriptiveWindowName",
"width=420,height=230,resizable,scrollbars=yes,status=1"
);
It depends what HTML version you use and if you care about W3C validation. In HTML5 you can use target="_blank" but with previous XHTML versions you couldn't and you had to use JavaScript to achieve the same result and make your site W3C valid. I think that's the only reason why many people used this method.
Of course using Javascript makes that user has to have JavaScript enabled to open this link in new window (and using adblocks/ghostery and similar addons make block some JavaScript) so I think if you only can, you should use target="_blank"
Window.open requires Javascript and can be blocked by popup stoppers. However, it does have additional options (width, height, options, etc). On mobile browsers, many options will be ignored.
It is preferred to use _blank as it is native to HTML whenever possible.