Receiving parameters with Js in HTML

Source: Internet
Author: User
First, we will introduce the method for processing URLs in JS: URL example: http: // localhost/test/test.htm? Id = 1
  • <SCRIPT merge Ge = JavaScript>
  • Alert (window. Location. pathname); -- returns/test/test.htm
  • Alert (window. Location. Search); -- return? Id = 1
  • Alert (window. Location. href); -- Return http: // localhost/test/test.htm? Id = 1
  • </SCRIPT>
  • --------------------------------- The location object contains information about the current URL. The entire URL string of the href attribute.
    The Protocol contains the first part of the URL, such as http:
    Host contains a string containing the host name in the URL: port number, for example, // www.zzcn.net/server/
    Hostname a string containing the host name in the URL. For example, http://www.zzcn.net /;
    Port contains the possible port number strings in the URL.
    The part after "/" in the pathname URL. For example ~ LIST/index.htm
    String after hash "#" (CGI parameter.
    Search "? "# (CGI parameter.

    Functions used to receive Parameters Using Js in HTML
    Function getparameter (PARAM)
    {
    VaR query = Window. Location. search;
    VaR ilen = Param. length;
    VaR istart = query. indexof (PARAM );
    If (istart =-1)
    Return "";
    Istart + = ilen + 1;
    VaR iend = query. indexof ("&", istart );
    If (iend =-1)
    Return query. substring (istart );

    Return query. substring (istart, iend );
    }

    When used: var temp = getparameter ("passed parameters ");

    Xx.htm? Xx = xx. Haha ,,,

     

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.