HTML/Javascript simple redirect -works in IE/Opera but not in Chrome/Firefox

321 views Asked by At

I have a HTML page, which just creates a URL to a daily MP3 Can someone please help me, i get it to work in IE and Opera, but not in Chrome and FireFox The page simply does nothing in Chrome/Firefox, whilst it downloads the file in IE/Opera

<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <script>
    function yyyymmdd(dateIn) {
        var yyyy = dateIn.getFullYear();
        var mm = dateIn.getMonth() + 1; // getMonth() is zero-based
        var dd = dateIn.getDate();
        return String(10000 * yyyy + 100 * mm + dd);
     }

        var today = new Date();
        var p = 'http://www.test.com/' + yyyymmdd(today) + '.mp3';
        window.navigate(p);
    </script>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>

</body>
</html>
1

There are 1 answers

0
Nevin Chaushev On BEST ANSWER

You can use window.location.replace(p); instead of : window.navigate(p);

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<script>

function yyyymmdd(dateIn) {
    var yyyy = dateIn.getFullYear();
    var mm = dateIn.getMonth() + 1; // getMonth() is zero-based
    var dd = dateIn.getDate();
    return String(10000 * yyyy + 100 * mm + dd);
 }

    var today = new Date();
    var p = 'http://www.test.com/' + yyyymmdd(today) + '.mp3';
   // window.navigate(p);
   window.location.replace(p);


</script>
<meta charset="utf-8" />
<title></title>
</head>
<body>

</body>
</html>