Using JavaScript to get the URL of the current page is a complicated question, and if you think about it for the first time, many people are wondering what kind of javascript function it is.
Actually, the function that JavaScript gets the URL of the current page is the window.location.href that we often use to redirect.
For example, the following function:
- <script>
- var url=window.location.href;
- var loc = url.substring (Url.lastindexof ('/') +1, url.length);
- Alert ("url=" +url+ ", loc=" +loc);
- </script>
If the URL of the current page is http://localhost:6666/myphp/mobile/pc1.php, then it runs as follows:
The above function shows how to get the current page name.
After obtaining the entire URL using the variable of window.location.href, which part of the address to use, using string processing functions such as substring,indexof to handle the obtained URL, intercept the part you want.
Usually use Window.location.href to redirect, is to change the URL of the entire browser,
If there is no assignment later, this becomes the statement that gets the current value.
As with document.getElementById ("XX"). Value, you can modify it to get it.
Cocos Creator get current URL take parameter