I want a simple thing, but I am not getting it to work  Just like the browser change the confirmation text from      "Are you sure you want to leave this page?"   to      "Are you sure you want to reload this page?"   depending what you are doing, I want that my custom confirmation text also knows which action the user is performing.  Currently I have this:  window.onbeforeunload = function (event) {     var infoText = (event.srcElement == event.target) ? "Reloading" : "Movig from";     infoText += " this page will cause you to lose current information.";     return infoText; };   I thought that comparing the event.srcElement vs. event.target will be enough as they have the navigation links. But that if statement always returns true, so it always looks like it is reloading even if the destination link is different.  As the browser knows, I thinks there must be some way to do it. If not, I'll have to create a generic message. (Obviously I could make it generic and... done. But now I really want to know it.)
68479
I am currently looking at the "unload" event of a window to try to determine how the "unload" event was triggered, but am having little success. Is there a way to determine how the javascript event was triggered?   Page Refresh Back Button (or navigate away from the page) Closing the Browser   Essentially I need to execute some code only when the browser window is being closed, not refreshed or navigated away from.  Purpose: When a customer does an update of our software, the update will redirect their first Internet request to an offer page. There is a button for a "Do Not Bother" option, but some users will simply close their browser. Upon closing the browser, I need to duplicate the "Do Not Bother" functionality so the user no longer gets redirected to the offer page. Simply attaching to the "unload" event will not work due to the different ways of leaving a page.
71695
This code always works, even in different browsers:  function fooCheck() {   alert(internalFoo()); // We are using internalFoo() here...    return internalFoo(); // And here, even though it has not been defined...    function internalFoo() { return true; } //...until here! }  fooCheck();   I could not find a single reference to why it should work, though. I first saw this in John Resig's presentation note, but it was only mentioned. There's no explanation there or anywhere for that matter.  Could someone please enlighten me?
50903
I'd think this would work just fine, but it seems to prevent the action function from firing regardless of the confirm response  &lt;apex:commandButton value="Remove All" action="{!removeAll}" rerender="form"      status="LoadingStatus" onclick="return confirm('Are you sure?');"/&gt;
22840
I'm building an HTML UI with some text elements, such as tab names, which look bad when selected. Unfortunately, it's very easy for a user to double-click a tab name, which selects it by default in many browsers.  I might be able to solve this with a JavaScript trick (I'd like to see those answers, too) -- but I'm really hoping there's something in CSS/HTML directly that works across all browsers.
104314
I do some minor programming and web work for a local community college. Work that includes maintaining a very large and soul destroying website that consists of a hodge podge of VBScript, javascript, Dreamweaver generated cruft and a collection of add-ons that various conmen have convinced them to buy over the years.   A few days ago I got a call "The website is locking up for people using Safari!" Okay, step one download Safari(v3.1.2), step two surf to the site. Everything appears to work fine.  Long story short I finally isolated the problem and it relates to Safari's back button. The website uses a fancy-pants javascript menu that works in every browser I've tried including Safari, the first time around. But in Safari if you follow a link off the page and then hit the back button the menu no longer works.  I made a pared down webpage to illustrate the principle.  &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&gt; &lt;html&gt; &lt;head&gt;&lt;title&gt;Safari Back Button Test&lt;/title&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt; &lt;/head&gt; &lt;body onload="alert('Hello');"&gt; &lt;a href="http://www.codinghorror.com"&gt;Coding Horror&lt;/a&gt; &lt;/body&gt; &lt;/html&gt;   Load the page and you see the alert box. Then follow the link off the page and hit the back button. In IE and Firefox you see the alert box again, in Safari you do not.  After a vigorous googling I've discovered others with similar problems but no really satisfactory answers. So my question is how can I make my pages work the same way in Safari after the user hits the back button as they do in other browsers?  If this is a stupid question please be gentle, javascript is somewhat new to me.
65546
When a C# WinForms textbox receives focus, I want it to behave like your browser's address bar.  To see what I mean, click in your web browser's address bar. You'll notice the following behavior:    Clicking in the textbox should select all the text if the textbox wasn't previously focused. Mouse down and drag in the textbox should select only the text I've highlighted with the mouse. If the textbox is already focused, clicking does not select all text. Focusing the textbox programmatically or via keyboard tabbing should select all text.   I want to do exactly this in WinForms.  FASTEST GUN ALERT: please read the following before answering! Thanks guys. :-)     Calling .SelectAll() during   the .Enter or .GotFocus events won't   work because if the user clicked the   textbox, the caret will be placed   where he clicked, thus deselecting all   text.      Calling .SelectAll() during the .Click event won't work because the user won't be able to select any text with the mouse; the .SelectAll() call will keep overwriting the user's text selection.      Calling BeginInvoke((Action)textbox.SelectAll) on focus/enter event enter doesn't work because it breaks rule #2 above, it will keep overriding the user's selection on focus.
22242
I'm in a bit of a verbiage bind. I have a form for a request cancellation. I cannot change the wording on that. The word cancel HAS to be used.  The button bellow sits in the footer of a card. Unfortunately, I cannot show you the rest of the card for context.      Clicking that button brings up the above form in the footer of the card.  The pattern shown here (form input on one line, followed by a cancel and submit button with the below styles and ordering) is used across the application. This is another non negotiable. Clicking that cancel button collapses the form back into the original button ("Cancel Request").  As you can probably tell as this point, I have a Cancel-Cancel-Conundrum. I need a better word than cancel for that form button, but I'm having trouble thinking of something. I was thinking something along the lines of "Exit" but that feels a little weird.
117259
I have a form created by a custom module. Now I want to show an alert like ("Please fil the complete form before navigating otherwise lost all the data") if the user navigate to another page without filling all required fields.  How can I do so?
61656
I've got a message sent to me from a moderator which appears in the top-left notification dropdown box.  Clicking on the "item" brings me to a page where the message is shown. But after reading it I've closed the browser tab.  How can I get to the message page again?
27357
In my experience, input type="text" onchange event usually occurs only after you leave (blur) the control.  Is there a way to force browser to trigger onchange every time textfield content changes? If not, what is the most elegant way to track this “manually”?  Using onkey* events is not reliable, since you can right-click the field and choose Paste, and this will change the field without any keyboard input.  Is setTimeout the only way?.. Ugly :-)
74715
I have several input and option elements on my page, each (well almost) have an event attached to update some text on the page once they change. I use jQuery which is really really cool :)   I also use Microsofts  framework, utilizing the UpdatePanel. The reason why I do that is that certain elements are created on the page based on some server-side logic. I don't really want to explain why I use the UpdatePanel - even if it could (it can with quite some effort) be rewritten to use only  I still want that UpdatePanel.  You probably guessed it - once I have a postback on the UpdatePanel the jQuery events stops working. I actually was expecting this, since the "postback" is not really a new postback so my code in document.ready that binds the events won't be fired again. I also confirmed my suspicion by reading up on it in the jQuery help libraries.  Anyway I'm left with the problem of rebinding my controls after the UpdatePanel is done updating the . I preferably need a solution that does not require adding more .js files (jQuery plug-ins) to the page but something as simple as being able to catch the UpdatePanel's 'afterupdating' where I can just call my method to rebind all the form elements.
37444
When reviewing a question in the Reopen Votes queue, there are two main options: Leave Closed and Nominate for Reopening.  If I click Nominate for Reopening, a message box appears asking me if I am sure I want to vote to reopen:    If I click cancel, a second message box appears with the same question.   If I click cancel on the second message box is dismissed the message box, but nothing else happens.  If I click okay, a second message box appears with the same question.   If I click okay on the second message box is dismissed the message box, and a vote to reopen is cast. If I click cancel on the second message box is dismissed the message box, and a vote to reopen is cast.    I haven't yet exhausted all possible ways of interacting with these message boxes, but there is definitely at least one bug here.    A similar, and possibly related issue exists with the Leave Closed option. If I click Leave Closed, a message box appears asking me if I am sure I want to vote to reopen:    If I click cancel, the message box is dismissed, and my vote to leave closed is cast.  If I instead click okay the message box is dismissed, and my vote to leave closed is cast, but I occasionally see the error, "An error occurred when reviewing this item. Please try again."    Using Google Chrome Version 27.0.1453.116 m
37456
If you are editing a question and decide to close the tab/window/whatever, SO opens up a dialog box asking you if you are sure. The buttons for this dialog are "OK" and "Cancel". However, what these map to is not entirely obvious. It would make more sense to change them to action words describing what they do. For example, it could be "Close this Question" and "Stay Here". This would eliminate the need to explain which button does what in the dialog itself and require less work from the user.
69887
Current situation:  I am currently browsing a page (say, www.google.com). I want to open a bookmarked page (say, www.bing.com), but I want to keep the current page (Google) opened. I need to click on new tab, then click on the bookmark for Bing. Alternatively, I can right click and open Bing in new tab.  But I want none of those because why click twice when one is enough?    What I want:  I am currently on Google. I want to open Bing, so I click on the bookmark and Bing opens in a new tab. Google remains open.    I am aware of a duplicate question linked . However it didn't really provide a satisfactory answer. Changing every link to javascript breaks the icon and is a pain to do; middle clicking doesn't really work because I'm on a laptop and the touchpad does not support middle clicking. I hope there is an extension for Chrome that can redefine this behavior to the way I want. A hidden setting in Chrome would be even better but I doubt Chrome offers that.
112837
I'm implementing a redirect in a Lightning component, but it's opening in a new browser tab. I want the redirect to happen in the same tab:  navigate : function(component, event, helper) {  var urlEvent = $A.get("e.force:navigateToURL");   urlEvent.setParams({     'url': 'http://www.myurl.com'   });   urlEvent.fire(); }   Is there a way to force it to redirect in the same browser tab?
25663
How would I have a  action that may have some effects on the current page but would also change the URL in the browser so if the user hits reload or bookmark, then the new URL is used?    It would also be nice if the back button would reload the original URL.  I am trying to record JavaScript state in the URL.
210
I understand a few similar questions have been asked, but this is hopefully completely separate functionality.  Say you have Facebook open in Tab 1 of your favorite browser (mine is Chrome). When someone posts on your wall, comments, adds you as a friend (the list goes on), you get a number in the title of the page(tab) saying Facebook(1), indicating some sort of activity. The same thing happens if you're ON the page itself, I presume there is a notification ticker of some sort.  I already love the new  logo which does show notifications but only when you refresh look at the page.  I often find myself at work answering a question here and there and then I forget about it and do some actual work. 4 hours later, I click on my profile and BOOM, you have 8 comments, probably because you forgot to .Dispose() of an object or something :)  If my Stack Overflow tab title showed something like      (4) What's your favorite C# book?   Or, for pinned tabs, a browser will also indicate the title changed:    It would attract my attention to go and see who's complaining about my answer, if the OP needs more information or whether someone is just happy with my post.  So rather than refreshing Stack Overflow on an hourly basis, could we automate this and make our lives easier?   What do you think?