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:
Login page with a login form - HTML5 + CSS3
Application page (pop-up window) - purely ExtJS
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!
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" />
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.
Related
In an asp.net web application, I have a modal popup built with a Telerik Rad Window. In that popup there is a button which must do some action in its "code-behind" and then redirect the application to another page.
For the redirection I use the javascript command 'top.document.location.href = myPage' (sent to the browser from the code-behind with a ScriptManager.RegisterClientScriptBlock(...)).
This solves my problem but it is not very nice. When the button is pressed, this triggers the post-back. In the browser the popup is covered by a RadLoadingPanel which disapper when the post-back is finished. Then during a few seconds, nothing happens in the application and it is only after some time that the browser loads the new page.
The fact that nothing happens during a few second is not great since a user cannot know what the application is doing.
What can I do ? Is there a better way to do the redirection ? (I'm very new to javascript programming...).
Instead of just calling 'top.document.location.href = myPage', you can call a function that displays an overlay (e.g. show a RadAjaxLoadingPanel over the parent page body) and then set the new URL. See http://www.telerik.com/help/aspnet-ajax/ajxshowhideloadingpanel.html for info on how to show loading panels with JavaScript.
I think the delay after you set location.href is normal - the browser/server take some time to retrieve the new page HTML so the old page cannot go away instantly.
I am writing an ASP.NET 3.5 web app that displays a list of items. I want to be able to display a non-modal popup with details when the user selects an item. I want to be able to display several detail popups simultaneously. (i.e., the user can click an item to see its details, then click another item to get another popup.) Currently I call RegisterStartupScript during postback to write a "window.open(...)" script to the page when it re-renders. The problem, of course, is that this requires a full page postback and refresh.
It occured to me that this might be a perfect use for XMLHttpRequest or AJAX but I don't know how to do it (or whether it's even possible or smart to do this). Can someone show me the way?
I have the AJAX Extensions installed but I'd prefer not to use the AJAX Control Toolkit.
EDIT:
Some clarification: When the user selects an item a custom event is raised. On the server I handle this event and use some server-side logic to construct a URL which I then use with RegisterStartupScript to construct a "window.open(myUrl...)" script. But posting back the whole page to do this seems inefficient and I'd like to know if I can just make a call to a simple server-side function that constructs the url and sends it back without having to roundtrip the entire page.
Creating a popup has very little to do with AJAX, and a lot more to do with JavaScript. See the jQuery dialog library here. You can then use jQuery's AJAX API to do your server dirty work :)
jQuery Dialog UI
--
Bill Konrad
Devtacular - Web Development Tutorials
You can use DHTML Window widget.
It offers many way to display either modal or non modal window.
Also it supports AJAX.
You can use dhtmlwindow for open a new window, or
dhtmlmodal to open a new modal window.
Of course, you can edit it to match your requirement.
Sample:
var insWindow = dhtmlmodal.open("insbox", "iframe","UserMaster.aspx?" + queryStr, "User Master", "width=425px,height=500,center=1,resize=0,scrolling=1", "recal");
Do you really need to open a new window? Opening an absolutely positioned DIV or a new layer on top of the current page in the same window is all the rage these days.
Edit:
I don't think it would limit the number of popups, there is some neat stuff that can be done these days with libraries like jQuery + jQuery UI, you can simply create as many of these DIVs/layers as you need and make them movable, resizable, etc. Only thing that real popups have and these do not is that they do not appear on the tab panel/taskbar.
Yes, you will be limited to the size of the window in which is the main page opened, however, I don't personally see it as a problem since most people surf in a maximized browser window anyways.
Implementation of the oldschool typical popup window is undoubtedly much easier for you, but it also runs into problems with end user popup blockers. Just had that problem # my work, they needed to make a popup during the certificate authentication process for some reason and as soon as Yahoo released a new version their toolbar, it quit working).
Currently we're opening a new aspx page with window.open. The window.open is in a javascript function (openNewWindow()) in the current aspx page which is called when an asp.net hyperlink control is clicked.
The links are dynamically created on the page by our framework and so I'd like to avoid changing that functionality.
The problem seems to be that when this new 'child' window is closed, session state is lost. I should mention that session is available in the child window just not in the 'parent' window after the 'child' window is closed.
Funnily enough, it seems that elsewhere in our application, if an open.window call is added to a page by using a ClientScriptManager.RegisterStartupScript call on the codebehind click event of a hyperlink control (rather than it calling a function that is coded in the aspx) session is preserved.
The latter solution would be difficult to implement in the current framework code without a significant change and all the regression testing that would entail.
Anybody got any ideas how to keep the session state alive after the close of the child window.
BTW this is occurring in IE7 and our app is asp.net 2.0 based.
Thanks in advance for your insightful and elegant solutions to this problem! ;o)
IE 7 changed the behavior of new windows. Basically, each window is opened in it's own process. Tabs are still opened in the same process.
This means that each new window will have it's own cookie bag. Which means that the new window does not have the Sesssion_ID cookie automatically assigned. The .Net link control will send the cookies to the new window. However, just opening a new window with straight javascript probably won't do that.
FireFox has been this way for awhile, and Chrome, I believe, has always been this way. IE 6 and previous shared process space, even for multiple windows so everything was shared between the two which caused no end of headaches for debugging sites strictly in IE.
UPDATE
Here's a link that describes the problem in detail. You'll notice that this behavior is somewhat inconsistent. The reason is that sometimes IE 7 decides to open the new window in its own process, and sometimes it opens it in a new one.
There are two real solutions. Either stop relying on session entirely (my first choice, and I have strong technical reasons for this) or you need to switch to a cookie-less session.
I should correct myself (sorry can't edit the original question) and say that the control firing the javascript to do 'window.open' is a link button not a hyperlink.
It happened in my Chrome also.
I solved this by adding:
<link rel="shortcut icon" href="../../img/favicon.ico">
in <head></head> in page which will be opened.
I've got a small little page that is going to be viewed from a BB. Here's my 2 questions:
If I "click" on the link to submit the page, I get the following error: "JavaScript: An error occurred while executing a script." I can tell my BB to emulate a Microsoft IE browser and I don't get this error. I hope to not use this option because I doubt my users will be able to figure this out.
I have a panel that has a text box and a button in it. I set the DefaultButton property of the panel to be the button so when someone hits the enter button, it fires the click event of the button. When I hit enter on my BB, it reloads the page. Does anyone know why and how to fix this?
Thanks
Javascript support isn't great on the blackberry, especially BBs running older software.
For #1 your site is outputting two different sets of HTML. Setting the browser type only the blackberry doesn't affect its rendering engine at all, it just sends a different header that makes asp.net think the client is running IE and there for it is sending different html/javascript.
For #2 I don't think the BB is going to do what you want. It is submitting the form but not setting the event target correctly. It may be easier to move your form handing logic into Page_Load inside an isPostback if statement. that way no matter how the form is submitted your code will run.
Both cases may be fixed by giving more details about the blackberry browser to asp.net. Here is an article that describes how to make a .browser file so that asp.net knows what type of HTML and JavaScript to send to the device.
In my ASP.Net application I have a requirement that when a user clicks on an UI element we generate a PDF for them which they can download. This is currently implemented by doing a form post to an ashx page. This page essentially inspects the form and then executes the correct server side page which either results in HTML or a PDF document of that pages HTML.
On the client I know ahead of time if we are going to be getting a PDF or HTML, when its an HTML I open a new window and direct the form post to that window and all works well. When its a PDF I don't change the target for the form and it remains on the current page.
This works, the user is presented with a save dialog, and the current page is not changed or lost.
The problem I have is that generating the PDF takes anywhere from 1-15 seconds. What I want to do is popup a please wait dialog. Displaying the popup is going to be easy, what I am not sure of is how do I know to close the popup? The popup will be a div in the current page.
The popup can have a client side timer which polls the server for task completion. The long running server task should update the progress in a database table or a server cache object which can be accessed by the polling service.
Couple of old articles from MSDN magazine. You should be able to use the same concepts with newer libraries like asp.net Ajax.
Reporting Task Progress With ASP.NET 2.0
Simplify Task Progress with ASP.NET "Atlas"
just have some javascript on the client side and let it show some animated GIF for 1-15 seconds (your choice) and close itself after the designated time.
Gulzar's suggestion was spot on. I have a simple ajax enabled wcf service which checks a session variable. My ashx page sets the variable to false when it starts processing and then true when its done.
I think there might be a race condition if the client checks before we set the session item to false; however, there are ways around that if we modify the service to set the session item to false after a client gets an im done response.
The tricks is still going to be figuring out what the intervalon the client should be. If we set it to low the user could save the file and then see the still processing message. I'm debating myself between half a second and a second. Anything less then a half a second seems unnessecary.
You said:
When its a PDF I don't change the
target for the form and it remains on
the current page.
If that is the case then the original page will be gone when the PDF is opened. In that situation I would have a loading animated gif and open it using Javascript into a div tag overlaying the rest of the page. You would not need to close it, so no timer or polling needed. It would just be gone when the page is gone.