Skillfully passing page parameters with JavaScript

Source: Internet
Author: User
Tags string split
The javascript| page recently had a strange need to pass parameters between static pages
I can't think how to solve pure HTML static page How to get the parameters?
Then suddenly thought of javascript all solved ...

Let me tell you a little bit about using JavaScript to accept parameters on a static page.
It's really simple. As long as the user opens the page URL with parameters
and JavaScript can get the URL of the current page simply parse the URL that gets it

Let's take a look at my code. Just embed the code in the paging file
<script>
Urlinfo=window.location.href; Gets the URL of the current page
len=urlinfo.length;//gets the length of the URL
Offset=urlinfo.indexof ("?"); /sets the position at which the parameter string starts
NEWSIDINFO=URLINFO.SUBSTR (Offset,len)//Fetch parameter string This will get a string like "id=1"
Newsids=newsidinfo.split ("=");//To split the obtained argument string by "="
newsid=newsids[1];//get the parameter value
Alert ("The parameter value you want to pass is" +newsid);
</script>

But be sure to remember that this method is only useful for URLs that contain parameters
If the other side uses the Post method to pass the parameter URL, it will not contain parameters.
So this trick is only useful for get methods or URLs that specify 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.