DorianHuxley
DorianHuxley

Reputation: 662

Javascript "window.location" stopping PHP redirect

Basically there's a callto function, and a timer. The timer is displayed visually via Javascript countdown, and at the same time there's a PHP redirect which has been set to the same length as the Javascript countdown. However, the window.location callto function is preventing the PHP header redirect from working. Can anybody tell me why?

The Javascript window.location function (located after body due to it preventing code below it from being processed:

<?
echo"
<script type='text/javascript'>
    window.location='callto:".$to."';
</script>";
?>

The PHP header redirect (above the html tag):

<?php

header( "refresh:5;url=wherever.php" );

?>

If I remove the window.location function the redirect works.

Upvotes: 0

Views: 749

Answers (3)

Honk der Hase
Honk der Hase

Reputation: 2488

 header( "refresh:5;url=wherever.php" );

This is NOT a valid redirecting header!

header('Location: http://example.com/sub/script.php');

THIS is a valid Redirect Header!

To make the script wait as you want , you'll need to add a Sleep on it:

sleep(5);
header('Location: http://example.com/sub/script.php');

Upvotes: 2

Tobias Golbs
Tobias Golbs

Reputation: 4616

Instead of a javascript redirect you should render an call-link with simple html and the href="callto:...". If you want to show the call screen without user interaction you only have to trigger a click event on the link.

Upvotes: 0

Packet Tracer
Packet Tracer

Reputation: 3924

you should redirect just with javascript, don't redirect with php. why doing a php redirect when you're doing it already with javascript?

In order to delay the redirect you should use Javascript setTimetout() function, such as:

setTimeout(function () {document.location = 'detination';}, time_in_miliseconds);

Upvotes: 2

Related Questions