flask / index.html
botsi's picture
Create index.html
8babdba verified
<!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>