This question already has answers here:
window.open() simply adds the url to my current url
(4 answers)
Closed 4 years ago.
I have a button that is located inside iframe with url="loclahost:3000" for example.
I have an event on this button that should open a new tab with another url for example "www.google.com". But when I click the button I am getting the new tab opened with the following url "http://localhost:3000/www.google.com"
I am using a window.open('www.google.com") function in order to open the new tab.
How can I remove the "http://localhost:3000/" from the new tab url?
The best way to do so would be to use an absolute link, which cancels out any relativity the URL might have:
var url = "https://www.google.com";
window.open(url);
Here the https:// signifies it's a completely different page to the current page, so the browser should open that link, not try and find a file by that name.
Related
This question already has answers here:
Open a URL in a new tab (and not a new window)
(33 answers)
Closed last year.
I'm developing a recommendations application written in React, and want the user to be able to be sent to external websites when the component containing the website's information has been clicked.
Currently, I have a wrapper that, when clicked, pushes the new URL to the history object from the React library. The source code is shown below.
<VStack onClick={() => history.push(<url here>)}>
<inside of component>
</VStack>
Unfortunately, the URL is being loaded in the same window, but I want the user to remain on the website, in the original tab.
Update your onClick function to
onClick={() => window.open(urlHere)}
see more of window.open here
You can perhaps try setting the target attribute to "_blank" in the Link tag itself.
example:
<Link to="/somewhere" target="_blank">anything</Link>
This question already has answers here:
Open a URL in a new tab (and not a new window)
(33 answers)
Closed 8 years ago.
Browser settings vary for allowing popups and I want my URL which is called within a JavaScript function to open in a new tab and not be considered a popup.I am opening the url as:
window.open(my_global_link,'_blank');
In IE and FireFox, when I click on the image I get a notification Pop-up blocked and only by Allowing pop-up for the site the URL would open in a separate tab. How can I make it open in a separate tab and not consider it a pop-up?
It is a browser setting . try finding navigation options for new tabs in the browser you are using and set it to open in a new tab instead off a new window.
This question already has answers here:
How do I modify the URL without reloading the page?
(20 answers)
Closed 8 years ago.
I am in a page with url
https://mysite.com/tst/v1/my-app/var/$%5Btest_new_var%5D.
On click i want to change the url to
https://mysite.com/tst/v1/my-app/" without reloading the page.
How can i do that?
please help,
Thanks.
In newer browsers that support history.pushState you can replace the url without reloading.
Lets say a user browses to http://example.com/ernie.html
window.history.pushState({ foo: "bar" }, "page 2", "bert.html");
Will change the address bar to http://example.com/bert.html, but won't cause the browser to load bert.html or even check that bert.html exists.
This question already has answers here:
Redirect parent window from an iframe action
(14 answers)
Closed 9 years ago.
I have a html page and on GO button i have write redirecting code
window.location.replace(url);
I put this page in iframe and on click on GO button result page should open in the existing page replacing the url of the browser but it is opning in iframe only...
I tried
<base target="_parent" /> also but no luck
window.top.location.href is what you're looking for.
Your result page needs to break out of the iframe:
http://www.w3schools.com/js/tryit.asp?filename=tryjs_breakout
This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Programmatically open new pages on Tabs
I have a link in my page and i want it to be opened in a new tab when the user clicks it?
That depends on the users browser settings. You can't control that as far as I know. All you can do is get it to open in a new windows, but if the user has his/her browser setup to open new windows in a new tab, it will do that.
So basically, the best you can do is open in a new window.
target="_blank"
i.e.
link text here
Most browsers treat a _blank target as opening in a new tab.
Set the target to _blank:
Use the target attribute set to _blank:
example
The exact behavior depends on the browser and user settings, so this is the best one can do.
This is considered bad practive because you (the web developer) is trying to control what the users browser is doing. It should be up to me how I want to open the link. Other than that lecture (and I understand that this may not be your decision), it doesn't seem that there is a way to do this.