Teslo.
Teslo.

Reputation: 501

Close current browser window or tab when popup opens

So, I've seen this approach on one site (I can't remember it, though) and it works like this:

First, there is a simple page with a simple login form. But when you click the login button of the form, if the validation of user and password is positive and the response from the server is positive as well, a new pop-up window appears (which contains the application written in javascript - ExtJS) and the current tab of the browser (which was the login form page) closes.

In my opinion, this is an excellent approach because the ExtJS is a single page application pattern, powerful enough to run full AJAX, without visible redirects. Plus, the pop-up scenario eliminates the browser page control buttons (back, forward, refresh) and the address bar is read-only.

Now, I'm trying to reproduce this by using the help of ASP.NET as server side scripting language, among ExtJS as the main application. So, the results would be as following:

  1. Login page with a login form - HTML5 + CSS3
  2. Application page (pop-up window) - purely ExtJS
  3. A web service - ServiceStack

The web service exposes the method for login purpose, as well as the other methods, and it always returns JSON responses. A session variable must be set (if the login was successful) before opening the pop-up and closing the window.

And here comes the question:

How can I accomplish this scenario of opening a pop-up and closing the current window/tab if the login was successful? Any help, hints, references, advices, criticism is totally what I'm expecting.

Thank you!

Upvotes: 1

Views: 5002

Answers (2)

Peter Ivan
Peter Ivan

Reputation: 1521

Keep away from opening pop-ups if you really don't have to. All modern browsers are set up to prevent you from opening pop-up windows by default.

AFAIK the only 100% scenario to open a new window (with target attribute) is a hyperlink clicked by user.
window.open() and even document.getElementById("hiddenLink").click() are blocked by certain browsers.

Are there any real positives of doing so or is it only a false novelty of that site? The reasons you state are all well with one-window scenario.

Upvotes: 0

fengd
fengd

Reputation: 7579

you should be able to close the current window after open another one.

window.open('new window url'); window.close();

I tried this on my box, and it works well on chrome and safari

<input type="button" onClick="window.open('popop.html'); window.close();" value="open" />

Upvotes: 1

Related Questions