How to read get request using Javascript?

后端 未结 5 739
孤城傲影
孤城傲影 2021-01-06 00:49

So I have html page called A.html it was called like this from B.html : A.html?varString=\"bla-bla-bla\" Is it correct for sending ar

5条回答
  •  说谎
    说谎 (楼主)
    2021-01-06 01:04

    Mostly you'd like to handle the parameters passed to your page in the server side, but if you got your reasons why to do it client-side, here's a small script i found:

    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];
    }
    

    i didn't test it, but i'm pretty sure it'll to the job.

    just use it like: gup('parameter') and it'll return the parameter value for you.

提交回复
热议问题