1

I'm not so sure of how to ask my question, will try my best to explain.

My HTML,

<a target="aaa" href="mmmmm.html?hai=aaa" onClick="return openlinkNew(this)">mmmmm</a>

its javascript:

function openlinkNew(a) {
    var aaa=a.split("?")[0];
    var tab1 = window.open(aaa.href, aaa.target);
    tab1.close();
    return false;
    }

What i need to do now is, to close the tab which contains mmmmm.html with no query string when user clicks a link in other page. I used var aaa=a.split("?")[0]; to split the url from its query string and used

var tab1 = window.open(aaa.href, aaa.target);
tab1.close();

to close that tab. But it is not working. Why? Any Suggestion?

user3784251
  • 520
  • 2
  • 10
  • 24
  • You cannot close any window using `window.close()`. You can only close windows that you opened manually using `window.open()`. If your browser has settings to allow pop-ups from your site, then `window.open(aaa.href, aaa.target)' will a new window with your `mmmmm.html` and `tab1.close()` will close that. In case your browser blocks your pop-up, you will get an error for calling close() on a window that doesn't exist. – Arkantos Feb 21 '15 at 17:52
  • I'm assuming that there's another tab open in your browser with url `"mmmmm.html` at the time you click on this href, correct ? If so, how is that tab with `mmmm.html` opened in the first place ? Are you doing through javascript ? – Arkantos Feb 21 '15 at 17:54
  • @Arkantos http://stackoverflow.com/questions/8135188/focus-tab-or-window i refered it. But need is to `reload` a existing tab (in same window) and `focus` it. I got an answer from that link. Is there any other good way to do this? – user3784251 Feb 21 '15 at 17:56
  • @Arkantos its `(mmmmm.html)` like a home page. It will always be opened. And when user clicks that link it will open again that tab. But not actually open it should reload and focus. – user3784251 Feb 21 '15 at 17:58
  • @Arkantos As you said when i use this code, it blocks pop-up. Is there any other good way to achieve this? – user3784251 Feb 21 '15 at 18:02
  • So do you see any console errors ? – Arkantos Feb 21 '15 at 18:02
  • @Arkantos no errors. Actually no problem with mozilla and IE. Only chrome blocks the popup and i manually allow the popup to make it work – user3784251 Feb 21 '15 at 18:08
  • 1
    Thats the reason we don't rely on window.open because it depends on user preferences. Best way to do this is to have actual tabs in a single page. That way you can have multiple tabs with only one tab focused at a given time. Have a look at `Togglable Tabs` at this [link](http://getbootstrap.com/javascript/). You can find several other tab plugins but that link is just to give you some idea. – Arkantos Feb 21 '15 at 18:09
  • @Arkantos Thanks and ok will look on it. Else will use a single page.(single tab). Dont we have any other way to do like this? – user3784251 Feb 21 '15 at 18:13
  • 1
    I suggest you use tabs within a single page. That way you'll have more control. And for your use case, where in the home page has to be reloaded you can just fire an Ajax call, get the updated content, update your home tab div just before moving focus to that tab :-) – Arkantos Feb 21 '15 at 18:17
  • @Arkantos Will try your idea. Thanks for such response. :-) – user3784251 Feb 21 '15 at 18:20

0 Answers0