File size: 1,606 Bytes
8babdba |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
<!DOCTYPE html>
<html>
<head>
<title>
How To Get URL Parameters using JavaScript?
</title>
<script src = "https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.0/FileSaver.min.js" integrity="sha512-csNcFYJniKjJxRWRV1R7fvnXrycHP6qDR21mgz1ZP55xY5d+aHLfo9/FcGDQLfn2IfngbAHd8LdfsagcCqgTcQ==" crossorigin = "anonymous" referrerpolicy = "no-referrer"> </script>
</head>
<body>
<h1 style="color:green;">
Omnibus
</h1> <b>
How To Get URL Parameters
With JavaScript?
</b>
<p> The url used is:
Current URL
</p>
<p>
Click on the button to get the url
parameters in the console.
<a href src="index2.html">go to index2</a>
</p>
<button onclick="getParameters()"> Get URL parameters </button>
<div id="output"></div>
<script>
function getParameters() {
let urlString = window.location.href;
let paramString = urlString.split('?')[1];
let params_arr = paramString.split('&');
for(let i = 0; i < params_arr.length; i++) {
let pair = params_arr[i].split('=');
document.getElementById('output').innerHTML = "<p>" + "Key is:" + pair[0] + "<br>" + "Value is:" + pair[1]+"</p>";
console.log("Key is:" + pair[0]);
console.log("Value is:" + pair[1]);
var blob = new Blob(["<p>" + "Key is:" + pair[0] + "<br>" + "Value is:" + pair[1]+"</p>"], {
type: "text/plain;charset=utf-8",
});
saveAs(blob, "download.txt");
}
}
getParameters()
</script>
</body>
</html> |