Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Save the whales
Aug 31, 2004

by T. Finn

0zzyRocks posted:

I need to have the user decide whether they want to save data on a webapp before navigating away. I wanted to use my own confirm window so I could capture what button was clicked. Is there a way to capture the button clicked on the default beforeunload event popup?

So, you don't want to prevent them from leaving, but you want to prompt them to save before leaving, right? How about this?

code:
var saved = false;

function save() {
  saved = true;
  alert('data saved!');
}

window.onbeforeunload = function() {
  if (!saved) {
    if (confirm('You have unsaved data.  Save??')) {
      save();
    }
  }
};

Adbot
ADBOT LOVES YOU

Save the whales
Aug 31, 2004

by T. Finn

ronin109 posted:

What Ether Frenzy needed was a button that could (a) contain an image, and (b) submit it's parent form (without the use of JS).

An input with type="image" does that. Whether the input sends x/y coordinates or a name/value pair is of no significance in this case.

Doesn't this have the same effect? (except not having the user see "mysubmit.x=20&mysubmit.y=30")

code:
<input type="submit" style="border:none;width:[foo]px;height:[bar]px;background-image: url('[baz]');" value="" />

Save the whales
Aug 31, 2004

by T. Finn

ronin109 posted:

Just one teeny-tiny addition to your solution would be the inclusion of "background-color: transparent".

Ah, right... drat rounded buttons. I must have missed SuckerPunched's post when I made mine because he included that part. His is nice too because it's still usable when they don't load your stylesheet for some reason, although it's missing the width/height attributes on the button. The only thing I'm not sure of is what happens when the height of the image is less than the height of the text. Although the text is being indented out of view and the height attribute is fixed, would it still stretch to fit the text? I don't have all the major browsers available to me right now so I'm not sure.

Save the whales
Aug 31, 2004

by T. Finn

Lumpy posted:

I love working with people who literally say "well, javascript isn't a real language, so I'm not going to bother learning it; I just need to hack this out and I'll never have to use JS again." Despite having said that for the first time two years ago and having to work with JS more than any other language.

+1. For some reason so many of my colleagues think JavaScript is "dirty" and everything you do in it is a hack. When a client asks for a complex UI they panic. And they think nothing of writing something like:

code:
<script>
var i = 0;
...
</script>
I mean, great... now window.i = whatever you left it at. Is that really what you meant to do? Do you declare a global i variable in every programming language you use?

Functions as first class objects is enough for me to take JS seriously. If you're used to working with a stricter language like Java, that concept is so refreshing and awesome. It really changes the way you think about programming in general.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply