[HOW TO] HTML Redirect

HTML and JS redirection methods.

1. HTML Implementation

<head>
<!-- Refresh current page ONLY -->
<meta http-equiv="refresh" content="10">
<!-- Redirect to other page after counting down -->
<meta http-equiv="refresh" content="5; url=hello.html"> 
</head>

2. JavaScript Implementation

<script language="javascript" type="text/javascript"> 
// Instant redirect
window.location.href='hello.html';
// Redirect when time up
setTimeout("javascript:location.href='hello.html'", 5000); 
</script>

3. JavaScript Implementation (w Counting Down)

<span id="totalSecond">5</span>
 
<script language="javascript" type="text/javascript"> 
var second = document.getElementById('totalSecond').textContent; 
 
if (navigator.appName.indexOf("Explorer") > -1)  { 
    second = document.getElementById('totalSecond').innerText; 
} else { 
    second = document.getElementById('totalSecond').textContent; 
} 
 
setInterval("redirect()", 1000); 
function redirect() { 
if (second < 0) { 
    location.href = 'hello.html'; 
} else { 
    if (navigator.appName.indexOf("Explorer") > -1) { 
        document.getElementById('totalSecond').innerText = second--; 
    } else { 
        document.getElementById('totalSecond').textContent = second--; 
    } 
} 
} 
</script>

4. Solve Firefox not Support innertext

<span id="totalSecond">5</span>
<script language="javascript" type="text/javascript"> 
if(navigator.appName.indexOf("Explorer") > -1){ 
document.getElementById('totalSecond').innerText = "my text innerText"; 
} else{ 
document.getElementById('totalSecond').textContent = "my text textContent"; 
} 
</script>

– – – – –

I’m JokerM.

This post was written by me.

To report a copyright issue or abuse, please contact [email protected].

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share on facebook
Share on twitter
Share on telegram
Share on whatsapp
Share on email