-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

5
  • There is no hash, or "ash" I can see. Commented Jan 18, 2015 at 23:27
  • Is the event listener triggered? Try adding an alert or something to check it. Commented Jan 18, 2015 at 23:31
  • is it not triggered with the click? Commented Jan 18, 2015 at 23:33
  • yes I am looking at that answer, the issue was with my confusion with the meaning of HASH and URL, which might created a duplicate Commented Jan 18, 2015 at 23:39
  • however, i need to change the whole URL Commented Jan 18, 2015 at 23:40

2 Answers 2

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/

Sign up to request clarification or add additional context in comments.

10 Comments

"The hash is meant to be a string". Yes, and "http://www.example.com/xchanges/" is a string.
ok ash was a typo in the question title.
exactly @Oriol thanks and I don't understand why my address isn't changing
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/
i need to only change the address with no other action needed. No page changes, no refresh, just the change of the address
|
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");
});

2 Comments

that is changing, refreshing, the page. I simply want to change the url with no action
Hmmm, ok then I think you must use AJAX for that. I am not an expert yet when it comes to AJAX.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.