1

I need to redirect to another page and when it's loaded I need to print an alert("HELLO");

I think something like this:

$.load(path, function() {
    alert.log("HELLO");
});

I have just used window.location but it is incorrect, because by changing my url I can't print the alert("HELLO");

Anyone can help me?

Talha Awan
  • 4,573
  • 4
  • 25
  • 40
JoeB
  • 201
  • 2
  • 4
  • 9
  • 1
    Do you have control over the `document` that you are redirecting to? – guest271314 Jul 28 '17 at 14:32
  • @guest271314 yep – JoeB Jul 28 '17 at 14:33
  • Have you tried using `jQuery()` alias for `.ready()` at the `document` that you are redirecting to? – guest271314 Jul 28 '17 at 14:34
  • That code is not going to redirect and there is no way to redirect a page and fire off code in that page with code in your page. – epascarello Jul 28 '17 at 14:36
  • 1
    You would need to pass a parameter to the next page, and server side scripting would have to generate the alert. Instead you could open up a child window, instead of redirecting, and then you could pop up an alert from your initial page. Let me know if you want to go this route. – David P Jul 28 '17 at 14:39

1 Answers1

2

You can change page via window.location as you have tried, but if you want to alert something in another page, this page should contain the script with the alert. In your new page simply add:

$(document).ready(function() {
  alert('HELLO');
})
P.S.
  • 15,970
  • 14
  • 62
  • 86
  • I am guessing that what he really wants is to pass a message to the next page, and display an alert for that. And of course that will require appending a parameter to the redirect, and server side scripting to handle it. – David P Jul 28 '17 at 14:36
  • @DavidPm if so, here is the answer about passing parameters: https://stackoverflow.com/a/19036954/6053654 – P.S. Jul 28 '17 at 14:43