-2

I have this url:

http://www.example.com/xchanges/?sfid=422&_sft_category=vodafone

And It should become:

http://www.example.com/xchanges/

On a click I am trying:

$('.filter').on( 'click', 'a', function( event ) {
  event.preventDefault();
  window.location.hash = "http://www.example.com/xchanges/";
});

But it doesn't change the URL

rob.m
  • 9,843
  • 19
  • 73
  • 162

2 Answers2

0

The hash is meant to be a string, like this comments hash is 28015985 (the full URL being How to change url as a string in a var on a click?).

Take a look at the following jsfiddle. It sets the hash to #somehash, then prints the current hash.

http://jsfiddle.net/t1ko1tny/1/

Community
  • 1
  • 1
dotty
  • 40,405
  • 66
  • 150
  • 195
  • "*The hash is meant to be a string*". Yes, and `"http://www.example.com/xchanges/"` is a string. – Oriol Jan 18 '15 at 23:32
  • ok ash was a typo in the question title. – rob.m Jan 18 '15 at 23:32
  • exactly @Oriol thanks and I don't understand why my address isn't changing – rob.m Jan 18 '15 at 23:32
  • 1
    So you want the hash to be `http://www.example.com/xchanges/`? So the full url to be `mydomain.com/mypage.html#http://www.example.com/xchanges/` – dotty Jan 18 '15 at 23:33
  • i need to only change the address with no other action needed. No page changes, no refresh, just the change of the address – rob.m Jan 18 '15 at 23:34
  • to http://www.example.com/xchanges/ - I did set up a string in my code which said it – rob.m Jan 18 '15 at 23:35
  • So you don't actually want to change the hash? Just the URL? – dotty Jan 18 '15 at 23:36
  • @rob.m So, do you want to replace all the URL? Or just the hash (the part after `#`)? – Oriol Jan 18 '15 at 23:36
  • yes exactly, what is the diff between hash and url? thought that what ash was, the url. Sight* – rob.m Jan 18 '15 at 23:36
  • The hash is the `#myhash` part of a URL, the URL is the full thing (including the hash). – dotty Jan 18 '15 at 23:37
0

You mean you want something like this: http://jsfiddle.net/s8mv41b0/

$('.filter').on( 'click', 'a', function( event ) {
 event.preventDefault();
 window.open("http://www.example.com/xchanges/","_self");
});
Michelangelo
  • 5,888
  • 5
  • 31
  • 50