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.