We may need to redirect your page from one page to another. Try to configure them on the server as much as possible. But there are many common scenarios where you need to use javascript to redirect the page.

Window.location object has properties and methods that you can use efficiently to redirect to different URLs using javascript efficiently. Location.replace and location.assign can be very useful. The replacement method keeps session history clean, and the assign method allows the user to track through the URL history.

Today we will discuss ways to redirect pages from one page to another using simple javascript functions..


// window.location
window.location.replace('http://www.example.com')
window.location.assign('http://www.example.com')
window.location.href = 'http://www.example.com'
document.location.href = '/path'

// window.history
window.history.back()
window.history.go(-1)

// window.navigate; ONLY for old versions of Internet Explorer
window.navigate('top.jsp')

// Probably no bueno
self.location = 'http://www.example.com';
top.location = 'http://www.example.com';

// jQuery
$(location).attr('href','http://www.example.com')
$(window).attr('location','http://www.example.com')
$(location).prop('href', 'http://www.example.com')

LEAVE A REPLY

Please enter your comment!
Please enter your name here

thirteen − nine =