GET URL parameter via Javascript
20 December 2008
No Comment
If you want to retrieve various URL parameters without using PHP you can also do it via Javascript.
The following function can be used to do that:
Source
function gup( name ){ name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); var regexS = "[\\?&]"+name+"=([^&#]*)"; var regex = new RegExp( regexS ); var results = regex.exec( window.location.href ); if( results == null ) return ""; else return results[1];}
To get the value simply call it this way:
var frank_param = gup( 'frank' );
Another easy solution would be to do it via PHP but it’s not as elegant:
<script type="text/javascript" language="javascript"> <!-- <?php echo("firstVar = $var1;"); echo("2ndVar = $var2;"); ?> // --> </script>
Like our posts? Then subscribe via Mail:
Similar Posts:
- Popup Script Javascript
- ActiveX Controls always on top.
Hiding Elements with getElementsByClass. - Creating a popup window
- Fixing Popularity Contest
- IE wont send referrer via javascript
Socialize:
|
|











Leave your response!