how to add target blank to an href.location hyperlink [duplicate] - javascript

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]');

Related

Can't access URL of created Pop Up window [duplicate]

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

How to launch a local .html file as a pop-up? [duplicate]

This question already has answers here:
Open a local HTML file using window.open in Chrome
(3 answers)
Closed 4 years ago.
I am wondering what I can add to make an .html or .htm file create a pop-up window instead of creating a normal window and load the content in that window. Is there a way to do this? I have no idea, thanks.
link text
target="_blank" makes the link open in a new window, now a new tab

How to open a new script in the same tab [duplicate]

This question already has answers here:
window.open(url) not opening new web page in the same tab
(5 answers)
Closed 6 years ago.
I have the code
window.open("http://localhost/xyz.php")
This opens the PHP file on a new tab, although the same window. I want to open this on the same tab. How do I do it.
I have tried window.open("http://localhost/xyz.php","_self") and window.open("http://localhost/xyz.php";"_self") but that does not work. I have also tried window.location.hrefbut nothing seems to work. Is there any other way?
Just use window.location object:
window.location.href = 'http://localhost/xyz.php';
Changing href property, changes the current page address to the one you give as a parameter...
Note: you could also use window.location = 'http://localhost/xyz.php';, as suggested in comment, which is a bit shorter; though, changing location.href is a bit more standard, being implemented since JavaScript 1.0, so it's available in all browsers...
try this
window.location.replace("http://localhost/xyz.php");
Please refer to Open a URL in a new tab (and not a new window) using JavaScript .
It is a decision of the user, not the programmer, if a new page is opened in a new tab or a new window.
Try use this in your js:
location.href = "http://localhost/xyz.php";

Refresh existing tab when someone clicks on new tab [duplicate]

This question already has answers here:
open url in new tab or reuse existing one whenever possible
(2 answers)
Closed 7 years ago.
I have strange functionality requirement. There are two websites which has link of each other. Clicking the link opens other website in a new tab.
However, when the other website is already open in a tab, all i want on button click is to refresh the existing tab instead of opening a new tab.
Is it possible implement this? And on all the browsers?
EDIT: This is different from other SO questions mentioned in the comments since user can open both the websites directly as well and in that case suggested answers doesn't work.
You can do it like this:
Click here
The first time you click that link the page will open in a new tab, but the next times it will refresh the same tab instead.
That's how WordPress refreshes the preview when writing posts.
Edit: This will only work if the other page is opened with this link.

Open link new window (not tab) with JavaScript without typing the URL twice? [duplicate]

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.

Categories

Resources