Grabbing Hash From Url?
I want it so that if someone visits: http://www.site.com/#hash It puts the data after the hash into the input box with the id url and then it submits the form. Here is my code: <
Solution 1:
you can use
if( window.location.hash) {
var hashVal = window.location.hash.substring(1);
$("#url").val(hashVal );
} else {
alert("no hash found");
}
Solution 2:
Try something like:
$(document).ready(function(){
var hash = window.location.hash;
$('#id').val(hash);
$('form').submit();
});
Solution 3:
window.location.hash
will give you the hash value from the url. You can use this code.
//Instead of empty value set whatever you want in case hash is not present
$("#url").val(window.location.hash || "");
Solution 4:
try to google for jquery.ba-hashchange.min.js, it needs to be used with jQuery
$(window).hashchange(function(){
$("#url").val(window.location.hash);
});
Solution 5:
You can use this plugin to do it - https://github.com/marklar423/jquery.hash it's pretty straightforward.
Example:
//get var page = $.hash('page');
//set
$.hash('page', 1);
Post a Comment for "Grabbing Hash From Url?"