Grzegorz
Grzegorz

Reputation: 3608

Javascript redirect window.location.url with .hash

I'm trying to make redirect and pass # parameters

// I'm at: http://example.com/index.html
var url = 'http://example.com/category.html';
var hash = '#testsite';

// Ignores # and all after
window.location.href = url + hash;

// Does not work, sets hash first, then redirects to url without maintaining hash
window.location.href = url;
window.location.hash = hash;

Is it possible to redirect like that using javasript?

Upvotes: 2

Views: 4985

Answers (2)

Dekel
Dekel

Reputation: 62676

Not sure what is templocation but this works great:

var url = 'http://example.com/category.html';
var hash = '#testsite';

window.location.href  = url + hash;

Upvotes: 1

Bhavesh Gupta
Bhavesh Gupta

Reputation: 176

Maybe you can try something like below

var url = 'http://example.com/category.html';
var hash = '#testsite';
window.open(url+"?hash="+hash,"_self");
//http://example.com/category.html?hash=#testsite

Upvotes: 0

Related Questions