2

I have an image map that I'd like to pass a query string parameter to via JavaScript.

The JavaScript is:

$(document).ready(function ()
{
$('#Map2')
.mapster({
fillColor: 'ff0000',
fillOpacity: 0.3,
mapKey: 'state',
areas : [{key : **ID**, selected : true}, {key : '4210', selected : true}],

});
});

If my URL was http://www.domain.com/index.asp?ID=9 How do I pass that ID parameter to the above JavaScript?

4

There is a hidden tool in SP called JSRequest. Here is some documentation on JSRequest.

You could add the following code to your javascript:

JSRequest.EnsureSetup();
var currentID = JSRequest.QueryString['ID']

You only need to do the EnsureSetup once after the page loads and then you can use JSRequest any number of times to get different parameters from the url.

7

While Rothrock's answer is certainly valid, especially if you are using SP 2010, if you are on SP 2013 there's an even easier way.

In SP 2013 there is a handy global function GetUrlKeyValue:

var currentID = GetUrlKeyValue('ID');

You can of course use that to get any query string parameter (even custom ones you are inserting), provided you know the key.

  • Wow. I've been working in 2013 for 2+ years now and never came across that in any example. I can't wait to use it! Thanks. – Rothrock Feb 15 '17 at 2:52
  • @Rothrock Yeah, it's amazing what goes undocumented, isn't it? – Dylan Cristy Feb 15 '17 at 12:57
  • Thank you Dylan, for me it was 2010 but thank you just the same!! – Mike Rooker Feb 16 '17 at 2:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.