0

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?

Alpha2k
  • 2,212
  • 7
  • 38
  • 65
  • 1
    Actually an infinite recursion occurs. You've overridden `window.close` with your own implementation, which calls itself. – Teemu Oct 07 '14 at 18:32
  • Try `self.close();` And look at http://stackoverflow.com/questions/19761241/window-close-and-self-close-do-not-close-the-window-in-chrome – Cheery Oct 07 '14 at 18:32
  • @Cheery neither its working with self.close ... – Alpha2k Oct 07 '14 at 19:09

1 Answers1

3

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.

Sridhar Gudimela
  • 564
  • 8
  • 14