Skip to content

Instantly share code, notes, and snippets.

@rheid
Created March 16, 2018 22:20
Show Gist options
  • Save rheid/f8547a9ac22cc0dc4eabc9e0267f9b71 to your computer and use it in GitHub Desktop.
Save rheid/f8547a9ac22cc0dc4eabc9e0267f9b71 to your computer and use it in GitHub Desktop.
CHANGE DEFAULT FORM BUTTON REDIRECT – THE SIMPLE WAY
function changeRedirect(options) {
for (var i = 0, buttons = document.querySelectorAll(options.selector); i < buttons.length; i++) {
var newOnClick = function(originalOnClick) {
return function(){
Nav.navigate = STSNavigate = function() {
window.location = options.redirectTo
}
originalOnClick()
}
}
buttons[i].onclick = newOnClick(buttons[i].onclick)
}
}
document.addEventListener("DOMContentLoaded", function(event) {
changeRedirect({
selector: "input[value=Save]",
redirectTo: "https://google.com"
})
changeRedirect({
selector: "input[value=Cancel]",
redirectTo: "https://bing.com"
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment