Skip to content

Instantly share code, notes, and snippets.

@taf2
Created February 3, 2014 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taf2/8787353 to your computer and use it in GitHub Desktop.
Save taf2/8787353 to your computer and use it in GitHub Desktop.
// in a script file - we can attach a listener to a form ... this code handles the case that the form is for creating and editing a record. the code below detects whether the UA supports pushState and rather than redirecting to get the new window state, it can do this client side and use pushState to set the URL correctly..
if (updateOnNew && typeof(window.history.pushState) == 'function') {
window.history.pushState("", "Edit Schedule", schedule.update_url + "/edit");
// update any local page state...
} else if (updateOnNew) {
window.location = schedule.update_url + "/edit"; // older browser must redirect on new update
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment