Read URL values in Javascript

Asked

Viewed 76 times

0

I need to read all the values of a URL (below) in Javascript, taking both the name and the value to store in a database.

cadastro.php?codigo=4355&nome=Renan&[email protected]&celular=66992541453&40=on&11=on

Can someone help me?

  • See if you can get help http://answall.com/questions/134065/qual-express%C3%A3o-regular-para-tratrar-uma-url/134078#134078

1 answer

-1

You can try something like this function below, and then use the variables at the end of the code.

function getUrlParameter(sParam) {
    var sPageURL = window.location.search.substring(1);
    var sURLVariables = sPageURL.split('&');
    for (var i = 0; i < sURLVariables.length; i++) {
        var sParameterName = sURLVariables[i].split('=');
        if (sParameterName[0] == sParam) {
            return sParameterName[1];
        }
    }
}

var mobile = getUrlParameter('mobile');
var index = getUrlParameter('index');
var table = getUrlParameter('table');

I hope it works.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.