Asked 7 years ago
9 Jan 2017
Views 1255
sarah

sarah posted

How to redirect one to another page in JavaScript ?

How to redirect one to another page in JavaScript ? what is the best code to do redirection one page to another in JavaScript ? is jQuery or dojo or any other framework do redirection best or pure JavaScript is enough ?
Rasi

Rasi
answered Nov 30 '-1 00:00

suppose you want to redirect to href of <a> element than it will be done by document.execCommand in JavaScript.


<a href="http://google.com" id='r'>
google</a>
<script type='text/javascript'>
 document.execCommand(document.getElementById('r').click()); 
</script>


it also used to automatically redirect <a> link in JavaScript
Phpworker

Phpworker
answered Nov 30 '-1 00:00


window.location='www.google.com';

above code will redirect to google.com from loaded page.
Post Answer