This question already has answers here:
Open a URL in a new tab (and not a new window)
(33 answers)
Closed 6 years ago.
How do I have a function that opens a new tab in the browser with custom html that is generated in the root tab?
You can do this
var x=window.open();
x.document.open().write('<h1>Test</h1>');
x.close();
Note that you cannot force it to be a new tab as that is a user preference (of new window / new tab)
Related
This question already has answers here:
Is There Any Way We Can Get Url Of PopUp Windows In Parent Window
(2 answers)
How to get url from popup? [duplicate]
(2 answers)
Closed 2 years ago.
I'm creating a new window and opening it on a new pop up window
var win = window.open(varforURl,"Login to Spot",'width=800, height=600');
On my next line I'm trying to get the URL of the window I just created and the pop up window is still opened.
console.log(win.document.URL);
What I expect to see is:
https://accounts.spotify.com/en/authorize?....
(This is the Url I passed with a variable, and it is in fact displayed on the page)
However, on my console I get about:blank
Any ideas why this is happening and how I can get the url for the window I created?
win.location.href
Should do the trick
This question already has answers here:
How to open link in a new tab in HTML?
(12 answers)
Closed 5 years ago.
I opened the external URL using javascript. But it opens in the same window I need to open it in new tab
onclick="window.location= '$url';
You can do it by using only html if you want :
some text
But by javascript this should work :
onclick="window.open('http://my.link.com', '_blank')"
This question already has answers here:
Open a URL in a new tab (and not a new window)
(33 answers)
Closed 5 years ago.
I'm trying to get a link in javascript to open a url in a new tab. I've found a number of posts for target="blank" using attribute and a couple other ways but can't seem to get it to work. Basically, if v_virt = "invoices" I just need the url to open in a new tab. Does anyone know the proper syntax?
if(v_virt=="invoices"){
location.href=('https://www.example.com/invoices/invoice?ProjectID=[#field:ProjectID]&InvoiceID=[#field:InvoiceID]', '_blank');
}
You have to use window.open() rather than location.href.
location.href changes the URL of the current page;
window.open() opens a new pop-up window navigated to the specified page.
For example:
window.open('https://www.example.com/invoices/invoice?ProjectID=[#field:ProjectID]&InvoiceID=[#field:InvoiceID]');
This question already has answers here:
JavaScript open in a new window, not tab
(15 answers)
Opening new window in HTML for target="_blank"
(3 answers)
Closed 8 years ago.
It's possible make a link open in a new window (not tab) with this:
Print
Is it possible to modify this slightly so that the JavaScript looks at the href of the link so you don't have to write it out twice in the code?
Print
this.href is a reference to the href attribute of the element when in the onclick handler.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Basic Javascript question: How to open a new window?
I have such a link wrapped in a div:
<div class="sponsor" target="_blank" onclick="location.href='http://www.sponsor.com"></div>
Actually what I need is this link to open in a new window. At this point it opens in the same page. Thanks!
window.open('http://www.sponsor.com','_blank');