I'm writing a process to alert the users when their session is about to end. I want a popup window (or alert) to appear, and I've got that much working, but more importantly I want them to be alerted even when their browser is in the background - either by having the popup come right to the foreground - on top of any other application, Or having their browser window flash in the taskbar.
Any ideas or suggestions how to do this? Is there maybe a property of the AJAX popup extender that controls this?
Thanks,
Paul
You can't put a popup in front of another application, however you can make the tab / title "blink" until they take notice.
Take a look at this solution https://stackoverflow.com/a/156274/935779
It is a JavaScript solution that may help.
A modal popup would be best for this. You don't need AJAX as you're not posting to the server.
Are you using jQuery? If so you can quickly and easily set up a timer which shows a modal dialogue box when the time expires.
On each page load, or on specific user actions you can reset the timer.
As for having the browser flash in the taskbar, I don't believe that's possible.
Related
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.
We have a website that needs to perform certain actions when a pop-up is being closed.
Note: Not a session end but just a popup being closed.
The solution we found so far, is catching the onunload of the page and then popup a page to perform the actions. When the new popup ends -> it hides itself and everybody's happy.
The problem happens with popup blockers, they seem to prevent our finalizer window from being executed.
Is there a way to force opening of this window? Is there a different way to execute this set of actions? (The actions are server side like closing a MF session that we opened etc.)
You can use dialogs instead of popups. For example, jquery ui dialog.
Then, the code for the dialog is on the same page and you can easily handle anything that happens on that page, closing of the dialog, popping the other one and so on...
cheers
I have an ASP.NET page which has an asp.net button control in it. When the user clicks on the button, the page will do some calculations and then close itself, but when I click on the button during post back, the page shows a blank screen. I want to show a loading message instead of this. I used javascript to show a div which was hidden intitially and shown when the user clicks the button, but when the post back happens, the screen becomes blank. Any idea how to show the loading messsage in this scenario?
Thanks in advance.
Do you really need to avoid ASP.NET ajax or JQuery?
If so: move the heavy processing into an invisible IFRAME. Action your form to the invisible IFRAME, or use javascript to set the location of the IFRAME.
Your 'loading' javascript will display fine. When the form inside the IFRAME completes it just needs to output some javascript to tell the 'parent' to go to location or refresh.
If you use Ajax to post back to the form asynchronously, you can use the UpdateProgress control. Here is a link to an article explaining how to implement the functionality:
How to make a Gmail-like loading indicator with ASP.NET Ajax
Basically, you can't using just postbacks. The browser draws the screen white while waiting for a response from the server. That message you set to show when the user clicks a button was the correct approach (so good work).
But the browser drew the screen white, thinking "Oh boy I'm about to get a response!" and then waited for longer than you think is appropriate.
The only thing you could try would be, in the response, make the very first thing to stream to the browser some sort of loading message that the browser can display while loading the rest (like the gmail loading screen). But personally, I think you could spend your time doing some other development.
You could try other techniques with AJAX though.
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).
Can I tell, using javascript, whether a user has clicked on the "X" icon on a browser dialog, or the "OK"/"Cancel" buttons? I have code I need to run when the window closes, but it will only run when OK or Cancel are clicked.
I currently capture the onunload event of the window. How can i accomplish this?
window.onunload = function() { alert("unloading"); }
Why do you want to do this? We can probably help you come up with a different design that doesn't require this if you tell us what you're trying to do.
However, to answer your question: it's not possible to catch that event in all cases. You cannot prevent the user from closing the browser or guarantee that your code will execute when they do. You can make it slightly annoying for them, but they can disable javascript, or kill the process, or reboot the computer. Using the unload function is the closest you can come to having some code that runs when the window closes (it will run in cases of normal shutdown or when the user navigates away).
If I understood correctly, your question is about a browser dialog, not the main browser window.
To answer your question, you probably cannot distinguish between the Cancel button and the X button of a browser dialog. They'll both end up just returning a false. If you need this level of control, you should consider writing your own simulated dialog (lightbox) instead of a real JavaScript dialog. Or perhaps look at existing frameworks/plugins with modal dialogs that give you the amount of control you need.
What about if he does ALT + F4?
To the best of my knowledge, you can't detect whether the user closed the dialog by clicking the Cancel button or the [x] button, since neither are exposed to you beyond returning the result of the action (e.g., confirm() as true/false).
You can hook into the document.onbeforeunload event to perform whatever cleanup action you require; I've done so myself by sending an asynchronous XMLHTTP request to the server to make sure the user's session gets cleaned up properly.
It is impossible to catch the closing of the browser and handle every other event that also causes a post back. You can try and many people have before you and failed.
Your best bet is to use onbeforeunload and learn how to deal with session timeouts on your serverside to clean up data.