I am redirecting from some page to index.html. Page redirect to index by using following address in the address bar: http://localhost/index.html?page.html
How can I read the value after ?
sign and insert it (page.html) into index.html file?
var url = window.location.href;
var params = url.split('?');
alert(params[1]);
window.location.search
along with substring
to remove the ?
More information can be found through the link regarding the property, but with regards to printing it on the page:
<script type="text/javascript">
var GET = window.location.search.substring(1);
document.write(GET);
</script>
You could also extract it with a RegExp. Maybe not ideal but a solution nonetheless:
var url = location.href.match(/\?(.+)/)[1];
Split()
the document.URL
by the lastIndexOf
and parse it from there:
var url=document.URL;
var urls=url.substr(url.lastIndexOf('?')+1,url.length);
console.log(urls);
// urls will contain everything right of the ?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.