Reputation: 4705
I want it so that if someone visits:
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:
<form method="post">
<input id="url" placeholder="Enter" name="url">
<input type="submit" id="visit" value="Visit" class="submit">
</form>
How can I do this?
Upvotes: 0
Views: 353
Reputation: 1130
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);
Upvotes: 0
Reputation: 31043
you can use
if( window.location.hash) {
var hashVal = window.location.hash.substring(1);
$("#url").val(hashVal );
} else {
alert("no hash found");
}
Upvotes: 3
Reputation: 336
try to google for jquery.ba-hashchange.min.js, it needs to be used with jQuery
$(window).hashchange(function(){
$("#url").val(window.location.hash);
});
Upvotes: 0
Reputation: 69915
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 || "");
Upvotes: 1
Reputation: 723
Try something like:
$(document).ready(function(){
var hash = window.location.hash;
$('#id').val(hash);
$('form').submit();
});
Upvotes: 1