Last active
January 17, 2023 17:48
-
-
Save Virksaabnavjot/bbe6f5fb5df98e3101d13cdcddba413c to your computer and use it in GitHub Desktop.
Programmatically passing URL parameters to IFrame src using JavaScript. Full article here: https://mrvirk.com/passing-url-parameters-to-iframe-using-javascript.html?utm_source=gist-header&utm_medium=content&utm_campaign=Passing+URL+parameters+to+IFrame
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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
Hi @entreri74 I havent tested a Gmaps embed myself and you haven't provided any specifics but
lets take this sample gmaps embed as an example, i believe it could work but will leave you to test
Here we have a sample gmap embed code
here seems the variable you will need to alter is uluru
const uluru = { lat: -25.344, lng: 131.031 };
so you could try something like this
Potential solution code
I believe this should work, but note google maps may have some policies around not tinkering with there code (like they do for adsense) so highly recommend you checking them out before you try something custom like this code.
hope this helps
regards
nav