snipt

Ctrl+h for KB shortcuts

JavaScript

javascript redirect with timeout

1
2
3
4
5
6
<script>
	function Redirect(){
		location.href = 'http://www.anothersite.com';
	}
	setTimeout('Redirect()',2000);
</script>
https://snipt.net/embed/c7712b90ab216c7fb3021def94be87fe/
/raw/c7712b90ab216c7fb3021def94be87fe/
c7712b90ab216c7fb3021def94be87fe
js
JavaScript
6
2019-07-28T19:00:12
True
False
True
Jun 13, 2013 at 03:21 AM
/api/public/snipt/46100/
javascript-redirect-with-timeout
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="o">&lt;</span><span class="nx">script</span><span class="o">&gt;</span> </span><span id="L-2"><a name="L-2"></a> <span class="kd">function</span> <span class="nx">Redirect</span><span class="p">(){</span> </span><span id="L-3"><a name="L-3"></a> <span class="nx">location</span><span class="p">.</span><span class="nx">href</span> <span class="o">=</span> <span class="s1">&#39;http://www.anothersite.com&#39;</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a> <span class="p">}</span> </span><span id="L-5"><a name="L-5"></a> <span class="nx">setTimeout</span><span class="p">(</span><span class="s1">&#39;Redirect()&#39;</span><span class="p">,</span><span class="mi">2000</span><span class="p">);</span> </span><span id="L-6"><a name="L-6"></a><span class="o">&lt;</span><span class="err">/script&gt;</span> </span></pre></div> </td></tr></table>
javascript, redirect