Last updated on May 18th, 2016 at 04:18 pm

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)

Extract URL parameters using Javascript

Get the query string value of passed in URI with javascript. We are using getmyuri function which basically extracts values using regular expressions.

<script type="text/javascript">
var myStr = 'http://www.mistonline.in/process?id=2193&name=john';
document.write ( getmyuri('name', myStr) );
// outputs: john
document.write("<br>");
document.write ( getmyuri('id', myStr) );
// outputs: 2193

function getmyuri(n,s){
n = n.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");
var p = (new RegExp("[\\?&]"+n+"=([^&#]*)")).exec(s);
return (p===null) ? "" : p[1];
}
</script>

From this script you can extract the desired parameter from browser URL.
Thanks 🙂 Enjoy!!!!!!

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)

Leave a Reply

Your email address will not be published. Required fields are marked *