0

I have been tasked with emulating a JavaScript alert without using a JavaScript alert. I also cannot use jQuery in this app. So far, I have JavaScript that opens a new window using window.open. When the user blurs away from the popup window I'm creating and then some new data loads in it, I need the window to focus again for the user. This works fine in IE, Chrome, and Firefox on this static HTML page; however, when I try the same thing from our ASP.NET application, it only works in IE. The window updates as expected, but it never refocuses for the user in other browsers.

Here's the code I use to re-focus the window:

window.onload = function() {
    window.focus();
};

To open the window initially from the ASP.NET app, I'm using:

ClientScriptManager.RegisterClientScriptBlock(GetType(), "OurWindow", "OpenTheWindow();", true)

I've tried lots of what's already out there (such as these) to no avail. Am I missing something?

Edit: I added a little location.reload(); to the first page to simulate a postback from ASP.NET, but that didn't change anything.

Community
  • 1
  • 1
mrcoulson
  • 1,331
  • 6
  • 20
  • 35
  • Possible duplicate of [window.focus() not working in Google Chrome](http://stackoverflow.com/questions/2758608/window-focus-not-working-in-google-chrome) – GottZ Oct 26 '15 at 23:48
  • I tried those suggestions. None of them worked in the ASPX context. I specified that in my original question. Trust me: I wish they had worked. – mrcoulson Oct 26 '15 at 23:55
  • ok lets keep it simple: it does not matter if you use asp.net or not. chrome will not let you do that. what you could use instead is desktopnotifications – GottZ Oct 27 '15 at 12:55
  • Then I'm confused because it totally works on the example I linked above in Chrome. It works in Chrome on those static HTML pages. It fails in Chrome when the .NET app gets involved. I feel like there's an unseen layer here. – mrcoulson Oct 27 '15 at 14:45
  • In the meantime, I've sorta cheated by closing the window on blur so that it gets re-created anew every time it is requested. Same-ish result for the end user. – mrcoulson Oct 27 '15 at 14:48
  • @mrcoulson the example above doesn't just add focus, it actually reloads the pages (it just happens quick so you don't see it). It's the same as doing this `w = window.open("http://google.com", "window1", "width=200")` – katzmopolitan Jan 07 '16 at 19:40
  • The static page you linked to does not work for me in Firefox now. If the pop-up is already behind the main window, clicking the link again leaves it behind so nothing appears to happen. – Nick Rice Apr 09 '16 at 07:56

0 Answers0