Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
148
rated 0 times [  151] [ 3]  / answers: 1 / hits: 32923  / 8 Years ago, tue, april 19, 2016, 12:00:00

I want to read out an url parameter using jquery and bind this one in a variable. I've seen a lot of ways to solve it but definitely no one worked for me.



http://relaunch.headonline.de/projekte/#filter=kataloge-database



-> I'm using a '#' instead of a '&' or '?'!



This is my 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');

More From » jquery

 Answers
72
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>




[#62494] Sunday, April 17, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
zaynerogerb

Total Points: 454
Total Questions: 109
Total Answers: 97

Location: Comoros
Member since Tue, Mar 14, 2023
1 Year ago
zaynerogerb questions
;