javascript - Get url parameter with jquery -
i want read out url parameter using jquery , bind 1 in variable. i've seen lot of ways solve no 1 worked me.
http://relaunch.headonline.de/projekte/#filter=kataloge-database
-> i'm using '#' instead of '&' or '?'!
this current javascript:
function $_get(param) { var vars = {}; window.location.href.replace( location.hash, '' ).replace( /[?&]+([^=&]+)=?([^&]*)?/gi, // regexp function( m, key, value ) { // callback vars[key] = value !== undefined ? value : ''; } ); if ( param ) { return vars[param] ? vars[param] : null; } return vars; } var filter = $_get('filter');
var url = window.location.href; var arguments = url.split('#')[1].split('='); arguments.shift();
working example
var url = "http://relaunch.headonline.de/projekte/#filter=kataloge-database"; var arguments = url.split('#')[1].split('='); arguments.shift(); alert(arguments)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
var url = window.location.href; var arguments = url.split('#').pop().split('=').pop();
working example
var url = "http://relaunch.headonline.de/projekte/#filter=kataloge-database"; var arguments = url.split('#').pop().split('=').pop(); alert(arguments)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Comments
Post a Comment