Reputation: 3495
I am using below javascript code. I want to stay on same page till user click on alert.
After click on alert page should redirect to SomePage.aspx
<script type="text/javascript">
function myFunction() {
alert("Some text...");
window.location = 'SomePage.aspx';
}
</script>
Please let me know what I missed here. Thanks.
Upvotes: 0
Views: 2352
Reputation: 1
Try Like this
Script
<script type="text/javascript">
window.alert = function (al, $) {
return function (msg) {
al.call(window, msg);
$(window).trigger("okbuttonclicked");
};
}(window.alert, window.jQuery);
$(window).on("okbuttonclicked", function () {
redirect();
});
function redirect() {
window.location.href = "http://www.google.com";
}
function myFunction() {
alert("Some text...");
}
</script>
Html
<input type="button" onclick="myFunction()" value="Click" />
Note :- This function is execute on every alert
ok button. But you also pass some additional parameter for preventing to execute.
And i also recommended to use confirm instead of this.
Upvotes: 0
Reputation: 18873
Instead of alert i think you need confirm box :-
<script type="text/javascript">
function myFunction() {
var conf = Confirm("Some text...");
if(conf == true){
window.location = 'SomePage.aspx';
}
else{ }
}
</script>
Upvotes: 2