Reputation: 2241
I can open a new page in SAME tab by using function on button click
This is the file current_tab.html:
<input id="openHere" type="button" value="Open Here" onclick="openHere()"/>
This is the file current_tab.js:
function openHere(){
window.open("new_tab.html","_self");
}
This new opened page must have a button which if pressed closes the tab:
This is the button in new_tab.html
<input id="close" type="button" value="Close" onclick="close()"/>
And this is the function on file new_tab.js:
function close() {
window.close();
}
When i press the Close button nothing happens, what am I missing?
Upvotes: 0
Views: 969
Reputation: 584
There are two reason for not working above code.
First you are using close() as method name in 15_1.html which is a built-in function name. So it never been called. So change it as something else like winClose().
Second, whenever you are referring as "_self" in window.open it is nothing but replacing or redirecting the same page which is initial page. window.close() can't be working directly on initial load page.
It may work in few browsers like IE and Safari but not work on Chrome and Firefox.
Better avoid this model of navigation for a multibrowser environment.
Upvotes: 3