views:

100

answers:

3

i hae a link like ( domain.com/jsapi?key=123456 )

hov can i get this "key" into my JS code? i use jQuery and i don't know about its are easy way to get this "key" into JS variable.

tanks for all.

+2  A: 

This plugin might helps: jquery url parser

key = $.url.setUrl($(yourlink).attr('href')).param('key');

(not tested)

RC
edited to add an example
RC
A: 

It's not jquery. It's pure javascript. You can use regexp.

str = "domain.com/jsapi?key=123456" # Take it from wherever you want
splitted = str.split(/\?key=([0-9]+)/)

Then you'll have an array in the "splitted" variable, it's second element (at the id 1) containing the value.

Damien MATHIEU
A: 

jQuery not needed. The query string is available from the DOM:

window.location.search.match(/key=([^&]*)/);

Which gives you an array that has your value in it.

gWiz