javascript - Passing value to JS function through URL on window load -


my page http://www.dinomuhic.com/2010/index.php loads showreel @ start of page using onload call in body this:

<body onload="sndreq('96')"> 

96 id of showreel in sql library. js function "sndreq" ajax call using jquery opens requested item , displays in main window.

now question: if want send link client opens specific item directly not have navigate through site?

something http://www.dinomuhic.com/2010/index.php?sndreq=234 (which of course doesn't work , opens showreel, because onload in body tag overrides it)

how can implement this? want able open specific items url if nothing passed through url should open item 96.

thank in advance. i'm sure pretty easy can't see it.

cletus

you need parse query string. find easiest way deal query string following. first, need extract query string url:

var querystr = window.location.search; // give ?sndreq=234 

then, can strip out ? , split each query string parameter array:

var parampairs = querystr.substr(1).split('&'); 

now can build hash table object of name/value pairs making query string:

var params = {}; (var = 0; < parampairs.length; i++) {     var parts = parampairs[i].split('=');     params[parts[0]] = parts[1]; } 

in onload, can use parameter thusly:

sndreq(params.sndreq); 

make sure code run within script in head of document it's computed before onload executed.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -