jQuery/Javascript page redirect with alternative


1
2
var your_url = 'https://nikunjvadariya.wordpress.com/'; //change this to your url
$(location).attr('href','your_url');

Above code works to redirect page in jQuery, but javascript code is good alternative here.

Using javascript to redirect your page using below code, which is better than jQuery, will do the job:

1
window.location.replace("https://nikunjvadariya.wordpress.com/");

Another javascript approach which will mock as if the URL is being clicked to redirect is:

1
window.location.href = "https://nikunjvadariya.wordpress.com/";

Even this will do the trick in javascript, which sets your URL in a window object and assigns it to anchor tag’s href attribute automatically:

1
window.location = "https://nikunjvadariya.wordpress.com/";

Book mark code for all browser using Javascript

This is example code and change sidebarurl as required.

==========================================

<div style=”float:right;margin-right:10px;margin-top:6px”>
<script type=”text/javascript”>
var sidebarurl = “http://www.example.com/&#8221;; // Change as required
var sidebartitle = “Best Blogger Templates”; // Change as required
var url = this.location;
var title = document.title;

function bookmarksite() {
if (window.sidebar && window.sidebar.addPanel){ // Firefox
window.sidebar.addPanel(sidebartitle, sidebarurl,””);
}
else if ( document.all ) { // IE Favorite
window.external.AddFavorite(url, title);
}
else if (window.opera && window.print) {
// do nothing
}
else if (navigator.appName==”Netscape”) {
alert(“Please click OK, then press <Ctrl-D> to bookmark this page.”);
}
}

if (window.sidebar && window.sidebar.addPanel) {
document.write(‘<a href = “javascript:bookmarksite();”><img src=”http://cdn2.iconfinder.com/data/icons/c9d/favorites_add.png&#8221; title=”Bookmark This Website”/></a>’);
}
else if (document.all) {
document.write(‘<a href = “javascript:bookmarksite();”><img src=”http://cdn2.iconfinder.com/data/icons/c9d/favorites_add.png&#8221; title=”Bookmark This Website”/></a>’);
}
else if (window.opera && window.print) {
document.write(‘<a href = “‘+sidebarurl+'” title=”‘+sidebartitle+'” rel=”sidebar”><img src=”http://cdn2.iconfinder.com/data/icons/c9d/favorites_add.png&#8221; title=”Bookmark This Website”/></a>’);
}
else if (navigator.appName==”Netscape”) {
document.write(‘<a href = “javascript:bookmarksite();”><img src=”http://cdn2.iconfinder.com/data/icons/c9d/favorites_add.png&#8221; title=”Bookmark This Website”/></a>’);
}
</script>
</div>

============================================