Breaking News
Home / Web / Javascript / How to redirect page to another url using Javascript?

How to redirect page to another url using Javascript?

Javascript Redirect URLSometimes we have to redirect a page to another location. This can be achieved by using Javascript window.location method in the HTML page  using the following snippet.

This script can be added anywhere on the page, however as a best practice it should be added at the beginning of the web page.

<script language=”JavaScript”>
// –>

Alternately, if we can call this same Javascript on onclick method of the href (anchor tag). This achieves result except this is when the user clicks on the link rather than automatically be redirected to another site or location as defined in the url.

<a href=”#”onclick=”window.location=’’; return false;”>Click here</a>

Javascript URL Redirect


Check Also

How to get video id from a Youtube url in Javascript?

Snippet e.g. if the youtube, video url is: The snippet will return xptDCPlSSfI var …

Advertisment ad adsense adlogger