How to obtain parameters for HTML-only static pages (passing page parameters using JavaScript)

Source: Internet
Author: User
There is a strange demand in recent work that requires passing parameters between static pages.
I am wondering how to obtain parameters for a pure HTML static page?
Then I suddenly thought of JavaScript to solve all the problems ......

Next, let me explain how to use JavaScript to accept parameters on static pages.
In fact, it is very simple as long as the URL of the page opened by the user has Parameters
Javascript can obtain the URL of the current page. You only need to parse the obtained URL.

Let's take a look at my code. Just embed the code into a page file. <SCRIPT>
Urlinfo = Window. Location. href; // obtain the URL of the current page
Len = urlinfo. length; // obtain the URL length.
Offset = urlinfo. indexof ("? "); // Set the start position of the parameter string
Newsidinfo = urlinfo. substr (offset, Len) // retrieve the parameter string and obtain a string similar to "id = 1 ".
Newsids = newsidinfo. Split ("="); // splits the obtained parameter string by "="
Newsid = newsids [1]; // obtain the parameter value.
Alert ("the parameter value you want to pass is" + newsid );
</SCRIPT>

 

But remember that this method is only useful for URLs containing parameters.
If the other party uses the POST method to pass the parameter URL, it will not contain the Parameter
Therefore, this technique is only useful for get methods or URLs with specified parameters.

Related Article

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.