I have a series of links, which I want to open in a new window. Once a window is open and a new link is clicked it should reload the window with a new url.
It works fine by providing a specified target (name) to window.open for a series of websites, but somehow after the google search page has been opened it opens up another window.
When I click Open w3school
and then Open React
the behaviour is as intended. If I click Open google search
and then another link it pops up in a new window.
Steps to recreate:
- Click
Open w3school
opens a new window (intended) - Click
Open React
reloads the page in the opened window (intended) - Click
Open google search
reloads the page in the opened window (intended) - Click
Open w3school
opens a new window (not intended)
The code below illustrates the issue.
Does anyone have an explanation of this behaviour?
<html>
<body>
<p>Click the button to open a new browser window.</p>
<button onclick="openW3school()">Open w3school</button>
<button onclick="openGoogleSearch()">Open google search</button>
<button onclick="openReact()">Open React</button>
<script>
function openW3school() {
window.open("https://www.w3schools.com", "mywindow", "popup");
}
function openGoogleSearch() {
window.open("https://www.google.com/search?q=javascript", "mywindow", "popup");
}
function openReact() {
window.open("https://reactjs.org/", "mywindow", "popup");
}
</script>
</body>
</html>