Reputation: 12530
I have this PHP code:
<?php
/*
DOING SOME PHP STUFF THAT WORKS HERE
*/
echo "<script type=\"text/javascript\">
alert('test1');
</script>";
header("Location: index.php");
?>
This php page is loaded within an iframe. The redirect works OK but the javascript is not executed. My guess is that the server doesn't send the HTML of this page but just executes the PHP code and then sends the redirect HTML.
Can I make the javascript execute first and then redirect?
Upvotes: 0
Views: 79
Reputation: 68536
A single line of code on JS will do using window.location
<?php
echo "<script>alert('test1');window.location.href='index.php'</script>";
Upvotes: 1
Reputation: 2763
Just do the redirection via javascript, try this:
echo "<script type=\"text/javascript\">
alert('test1');
document.location.href='index.php';
</script>";
Upvotes: 0