I am trying to work on a module where there is an option to show the JavaScript alert and then it should redirect to a php $url. My script is attached below.
$url1=$_SERVER['HTTP_REFERER'];
$url = preg_replace('/\?.*/', '', $url1);
echo "<script type='text/javascript'>alert('Quote Emailed Successfully.');
url = '<?php echo $url; ?>';
window.location='url';
</script>";
It is showing the alert but it's not redirecting.
url = '<?php echo $url; ?>';
You can't nest <?php ... ?>
blocks.
Just use the variable. You are in a double quoted PHP string literal, so it will be interpolated.
url = '$url';
window.location='url';
You are trying to redirect to the URL url instead of the value of the url
variable.
Remove the quotes.
window.location = url;
check this
<script>
$url1=$_SERVER['HTTP_REFERER'];
$url = preg_replace('/\?.*/', '', $url1);
echo "<script type='text/javascript'>alert('Quote Emailed
Successfully.')";
url = '<?php echo $url; ?>';
window.location='url';
</script>";
You are setting window.location to the value 'url' . Notice the quotes. You should use the declared variable url. Just remove the quotes, as shown below.
$url1=$_SERVER['HTTP_REFERER'];
$url = preg_replace('/\?.*/', '', $url1);
echo "<script type='text/javascript'>alert('Quote Emailed Successfully.');
var url = '<?php echo $url; ?>';
window.location= url;
</script>";
Try this
$url1=$_SERVER['HTTP_REFERER'];
$url = preg_replace('/\?.*/', '', $url1);
echo "<script type='text/javascript'>alert('Quote Emailed Successfully.');var url = '" . $url; . "';window.location=url;</script>";
or you can also do it like
echo "<script type='text/javascript'>alert('Quote Emailed Successfully.');
window.location='" . $url; . "';</script>";
you should use location.href to redirect to php url eg
alert("alert your text ");
location.href = <?php echo $url_name; ?> ;
If you doesn't need to confirm the redirection then using this script might help
<script>
alert('Your message');
setTimeout(locate,3000);
function locate()
{
window.location.replace('PHP URL');
}
</script>
If you need to confirm the redirection
if (confirm('Go to PHP URL'))
{
window.location.replace('PHP URL'); }
else
{
/* Do Something Else*/
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.