2

I want to close a window open by this javascript written in my landing html page .

window.open(location,"_self");

in the location html page I have a button where I tried with

<div onclick="javascript:self.close();">Xyyyy</div>
<div onclick="javascript:window.close();">Xxxx</div>

None of them work.

Note: my condition in I have to open the new window in the same place.

any help is appriciated

2 Answers2

1

I did a search on the subject and this page is what i found.

html (not mine)

<input type="button" name="Quit" id="Quit" value="Quit" onclick="return quitBox('quit');" />

JavaScript (not mine)

function quitBox(cmd)
{   
    if (cmd=='quit')
    {
        open(location, '_self').close();
    }   
    return false;   
}

There is even a test page.

I did a search for a bunny rabbit too (which isn't mine either).

enter image description here

Updated : Mar-12-2015

I did a search on the subject and this page is what i found.

I did a test with this code and confirmed it is not supported. The comments are good reading.

JavaScript (not mine)

function close_window() {
  if (confirm("Close Window?")) {
    window.close();
  }
}

html (not mine)

<a href="javascript:close_window();">close</a>

<a href="#" onclick="close_window();return false;">close</a>
Community
  • 1
  • 1
whoacowboy
  • 6,982
  • 6
  • 44
  • 78
  • I need to do this in the same window. This opens an other window. that is not expected for my scenario – Khaja Md Sher E Alam Mar 12 '15 at 04:15
  • 1
    I dont think that is even possible in current "safe" version of internet browsers. I ran into this issue too, and the best thing you could do, is to not use window.open, but create a custom "window" by javascript, which is only controlled by you. – Eda190 Mar 12 '15 at 06:54
0

I don't get completely what you are trying to do but here are some tips:

window.open("https://slackoverflow.com");

is used to open an entirely new window(can be used to open local files as well ofc)

window.close();

window.close() Closes the tab.

<a target="_blank" href="http://your_url_here.html">Page yada yada</a>

And this can be used to open a link or page in a new tab. If you play around with these for a little itll start to catch on.

I hope some of these ideas help and will help you put together what you are trying to accomplish :)

  • @Edamame, so are you looking to open a new 'tab' in a browser? There are a few ways with just html attributes, but I don't know of any way in javascript, that doesn't mean there isnt one though. – StephenRossi May 11 '17 at 16:30