Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access request query string parameters in javascript?

I've seen numerous solutions that utilize RegEx, and to be quite frank, that seems ridiculously excessive since javascript is so versatile.

There must be a simpler way to access request parameters.

Could somebody demonstrate for me?

like image 439
keeehlan Avatar asked Apr 26 '26 14:04

keeehlan


1 Answers

I found a useful method in the depths of the net.

function querySt(Key) {
    var url = window.location.href;
    KeysValues = url.split(/[\?&]+/);
    for (i = 0; i < KeysValues.length; i++) {
        KeyValue = KeysValues[i].split("=");
        if (KeyValue[0] == Key) {
            return KeyValue[1];
        }
    }
}

Downvotes and plugins aside, thanks anyways.

like image 134
keeehlan Avatar answered Apr 29 '26 02:04

keeehlan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!