How can I read a GET element from url via javascript?

This question already has an answer here:

  • How can I get query string values in JavaScript? 73 answers

  • You can try the following:

    if((window.location.href).indexOf('?') != -1) {
        var queryString = (window.location.href).substr((window.location.href).indexOf('?') + 1); 
    
        // "queryString" will now contain kerdesPost=fdasdas%20ad%20asd%20ad%20asdas
    
        var value = (queryString.split('='))[1];
    
        // "value" will now contain fdasdas%20ad%20asd%20ad%20asdas
    
        value = decodeURIComponent(value);
    
        // "value" will now contain fdasdas ad asd ad asdas (unescaped value)
    }
    

    JSFiddle

    This should get you what you need.

    链接地址: http://www.djcxy.com/p/17616.html

    上一篇: 如何在网址中放置一个JavaScript变量?

    下一篇: 我怎样才能通过javascript读取url的GET元素?