0

I got my page to open with JS, with

<a href="javascript:openNewWindow();">

Now, the webpage will open in _self. I need to find a way to get a link, that will close my window. This doesnt work:

<a href="javascript:window.close();">

Now what to do? Anyone knows a better way to close self window? The second script has to be in the opened page.

bcmcfc
  • 25,966
  • 29
  • 109
  • 181
  • 5
    As per [documentation](https://developer.mozilla.org/en-US/docs/Web/API/Window.close), `window.close()` should work fine. If it doesn't you have to provide more information. A complete example would be useful. – Felix Kling Nov 03 '14 at 14:41

1 Answers1

-1

This is a correction of my previous answer:

newwindow=window.open();
newdocument=newwindow.document;
newdocument.write("Hello World.<input type='button' value='close' onclick='window.close()' />");
newdocument.close();

as you can see, window.close() works ok.

For a specific example, you can use this -> create 2 files: 1. windowOpener.html

<html>
<body>
    <input type="button" value="open" onclick="window.open('newWindow.html')" />
</body>
</html>

2. newWindow.html

<html>
<body>
    <input type="button" value="close" onclick="window.close()" />
</body>
</html>

if you'll run windowOpener.html and click 'open' it will open 'newWindow.html'. clicking 'close' in the new opened window, will close it. voila.

Avi L
  • 1,558
  • 2
  • 15
  • 33