Skip to content

Instantly share code, notes, and snippets.

@ldijkman
Forked from Virksaabnavjot/index.html
Created January 30, 2022 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ldijkman/dd2e1beb8773ec1286186aad8ae90d82 to your computer and use it in GitHub Desktop.
Save ldijkman/dd2e1beb8773ec1286186aad8ae90d82 to your computer and use it in GitHub Desktop.
Programmatically passing URL parameters to IFrame src using JavaScript
<html>
<head>
<title>
Programmatically passing URL parameters to IFrame using JavaScript
</title>
</head>
<body>
<iframe id="myIframe" frameborder="0" marginwidth="0" marginheight="0" scrolling="NO" width="100%" height="100%"></iframe>
</body>
<script>
let myIframe = document.getElementById("myIframe");
let endpoint = "https://ads.mrvirk.com/";
let url_string = window.location.href;
let url = new URL(url_string);
console.log(url_string);
let size = url.searchParams.get("size");
console.log(size);
let geo = url.searchParams.get("geo");
console.log(geo);
let adsURL = endpoint+"?geo="+geo+"&size="+size;
console.log(adsURL);
myIframe.src = adsURL;
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment