Page Redirect in JavaScript

Page redirects can be used to redirect user to some other webpage or website depending on the choice.

Page Redirect Syntax

As there is not much to explain we directly jump to syntax and get awesome stuff working.

window.location.href = "New Location's URL"

Page Redirect Examples

All we need to do is attaching event Listeners to these buttons and get it working

<button class=”btn center-block btn-primary” onclick=”window.location.href=’'”>Google</button>

<button class=”btn center-block btn-primary” onclick=”window.location.href=’'”>Yahoo</button>

<button class=”btn center-block btn-primary” onclick=”window.location.href=’'”>Facebook</button>

<button class=”btn center-block btn-primary” onclick=”window.location.href=’'”>Amazon</button>

window.location.href = ""

Page Printing

Javascript can be used to print the content of the pages into a hardcopy. Below command will open the printer page to print the current contents of the webpage.


Simply paste this in your browser’s console and get a hard copy of whatever page you require.

Translate ยป