0

let say i have this script.

$('body').load('someurl.html#12', function(data){
    // my code to proccess data
});

in someurl.html how do i get the hash of this URL? in this case should be #12. when i try to parse it using window.location.hash what i get is the parent URL without hash of course.

Dariel Pratama
  • 1,607
  • 3
  • 18
  • 49
  • `'someurl.html#12'.split('#')[1]`? – Fabricator Jun 05 '14 at 05:15
  • duplicate of [How can you check for a #hash in a URL using JavaScript?](http://stackoverflow.com/questions/298503/how-can-you-check-for-a-hash-in-a-url-using-javascript) – JK. Jun 05 '14 at 05:15
  • @user3678068 : yes i know how to split the hash, my problem is when i parse the URL inside someurl.html the value is not someurl.html, instead it is index.html – Dariel Pratama Jun 05 '14 at 05:18
  • `window.location` contains the URL of the page that's running the script, not anything that it loads. – Barmar Jun 05 '14 at 05:21
  • @Barmar : so how do i get the hash inside that loaded file, any idea? – Dariel Pratama Jun 05 '14 at 05:22

1 Answers1

0

That can be done using jQuery BBQ Full reference from here

Parsing the query string or fragment from a URL

The jQuery.param.querystring and jQuery.param.fragment methods can be used to return a normalized query string or fragment from the current document or a specified URL. Complete usage information is available in the documentation.

// Return the document query string (similar to location.search, but with
// any leading ? stripped out).
var qs = $.param.querystring();

// Return the document fragment (similar to location.hash, but with any
// leading # stripped out. The result is *not* urldecoded).
var hash = $.param.fragment();

// Parse URL, returning the query string, stripping out the leading ?.
// qs is set to "a=1&b=2&c=3"
var qs = $.param.querystring( "/index.php?a=1&b=2&c=3#hello-world" );

// Parse URL, returning the fragment, stripping out the leading #.
// hash is set to "hello-world"
var hash = $.param.fragment( "/index.php?a=1&b=2&c=3#hello-world" );
Adel
  • 1,468
  • 15
  • 18