Hi,
I am trying to dynamically overlay a small flag icon over the bottom right corner of the first image of my landing page. Does anyone know if this can be done using
I am not very experienced with coding but I thought I could do something like this:
if getURLParameter('country') = 'United%States' then
<img src="us.jpg" class="img-responsive">
else if getURLParameter('country') = 'Canada' then
<img src="ca.jpg" class="img-responsive">
This is just a pseudo code kind of thing to show how I'm envisioning this. I have seen this dynamic flag insertion on landers I've ripped from Adplexity but now that I'm actually looking for it of course I can't find it anywhere! Lol.
Let me know your thoughts.
Yes, you can use your tracker's dynamic callout to display a different flag or image into your landing page based on the parameter you'd like utilizing a jQuery and the following custom scripts.
Here are the steps that you need to follow:
Step 1 - Add the following script in the <head> </head> section of your landing page
<script>
var country = decodeURIComponent(window.location.search.match(/(\?|&)country\=([^&]*)/)[2]).replace(/(\+|%20)/g, ' ');
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<div class="some random classes">
<div id="show-flag-img" class="some random classes">
<script>
$(document).ready(function() {
$(document).ready(function() {
var img = $('<img />').attr({
'class': 'img-responsive',
'src': 'files/flags/' + country + '.jpg'
}).appendTo('#show-flag-img');
});
});
</script>
Wow thanks Losid, very helpful. I've added it to my lander as you described, only issue now is that the flag isn't really in the position I was hoping it would be in. I'll show a picture of how it looks, basically the flag is appearing on the left below the image.

Any way to change the position of it, ideally so that it's on the top right corner of the big image?
My version, without jQuery, which is not needed here.
Step 1 - Add the following script at the bottom of your landing page
<script>
(function() {
var country = decodeURIComponent(window.location.search.match(/(\?|&)country\=([^&]*)/)[2]).replace(/(\+|%20)/g, ' ');
document.getElementById("img-flag").src = 'files/flags/' + country + '.jpg';
})();
</script>
wicked thanks jeremie I'll try this out... step 2 I can do for sure =D

<html>
<head>
<!-- The below script is for the dynamic changing flag -->
<script>
(function() {
var country = decodeURIComponent(window.location.search.match(/(\?|&)country\=([^&]*)/)[2]).replace(/(\+|%20)/g, ' ');
document.getElementsByClassName("img-responsive").src = 'flags/' + country + '.png';
})();
</script>
<!-- The below script is for calling out the country in the text -->
<script type="text/javascript">
function GetQueryString(name)
{
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if(r!=null)return unescape(r[2]); return null;
}
var usergeo=GetQueryString("geo");
if (!(usergeo)){
var usergeo="the US"
}else{
if(usergeo=="United Kingdom"){
var usergeo="the UK"
}else if(usergeo=="United States"){
var usergeo="the US"
}else if(usergeo=="Europe"){
var usergeo="Europe"
}else if(usergeo=="Australia"){
var usergeo="Australia"
}
}
</script>
<body>
<li class="breadcrumb-item">
<a href="https://google.com" target="_blank">Trending -</a>
</li>
<li class="breadcrumb-item">
<a href="https://google.com" target="_blank">Technology</a>
</li>
<!-- This is where I'd display the flag -->
<li class="breadcrumb-item flag">
<img src="flag.png" class="main-image">
</li>
<!-- Should I change the above code to: -->
<script>
$(document).ready(function() {
$(document).ready(function() {
var img = $('<img />').attr({
'class': 'breadcrumb-item flag',
'src': 'flags/' + country + '.png'
}).appendTo('#show-flag-img');
});
});
</script>
<!-- I'm trying to call out the country name but I think it has something with me having to add tokens to my lander in order for it to work-->
<strong>
Want to know how thousands in <script>document.write(usergeo);</script> are receiving welfare checks?
</strong>
<!-- This part I'm trying to get have my website dynamically change the image based on the viewer's location so same thing like the flag -->
<div class="text-center">
<a href="https://google.com" target="_blank" class="svg-holder">
<img src="map.png" class="main-image">
</a>




Hey,
See the script i wrote here that demonstrates how getElementsByClassName() and getElementById() work
https://stmforum.com/forum/showthrea...l=1#post402378
You can not directly use the src attribute after the function getElementsByClassName() because it returns an array of elements. If you only have one, give him an ID and use getElementById(). Don't replace by the code you suggested because it is awful.
else if(usergeo=="Europe"){
var usergeo="Europe"
}else if(usergeo=="Australia"){
var usergeo="Australia"

/* Got rid of what you suggested, but in order for this script below to work I have to set tokens in my lander url. Is that correct? Also, the variable can be only used once in this case. You can't use multiple if else cases */
<script type="text/javascript">
function GetQueryString(name)
{
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if(r!=null)return unescape(r[2]); return null;
}
var usergeo=GetQueryString("geo");
if (!(usergeo)){
var usergeo="the US"
}else{
if(usergeo=="United Kingdom"){
var usergeo="the UK"
}
}
</script>
/* In the below script, I would use the getElementbyID as I want only one spot to rotate the images depending on the user's geo. In the script below, I don't see a area where you would reference where to get the image to load. like this: 'flags/' + country + '.png'. The getURLParameter I would assume you would have to put some type of token for your lander to recognize what to put in there. */
<script>
var img_name = getURLParameter("pic");
/* Single Image -- getElementbyId */
var img_cl = "prizeImg1";
document.getElementById(img_cl).src = img_name;
/* Multiple Images -- getElementsByClassName */
var imgs_cl = "prize";
var imgs = document.getElementsByClassName(imgs_cl);
for (i = 0; i < imgs.length; i++) {
imgs[i].src = img_name;
}
function getURLParameter(name) {
return decodeURI(
(RegExp(name + '=' + '(.+?)(&|$)').exec(location.search) || [, null])[1] || ''
);
}
</script>
/* This will not work because the above location script is not correct? I will have to research more on this. */ <strong>Want to know how thousands in <script>document.write(usergeo);</script> are receiving super-fast internet speed for a fraction of the costs?</strong>
/* This is somewhat similar to the flags we want to dynamically pull in. The lander url will probably need to add tokens for the script to work */
<div class="text-center">
<a href="https://google.com" target="_blank" class="svg-holder">
<img src="map.png" class="main-image">
</a>
I don't want to be rude, but this is a mess. You have no idea what you are doing:
- mix of jquery / vanilla js
- you do not realize that getURLParameter / GetQueryString do the same thing
- ...
I am happy to give snippets of code for forum members to integrate, point in the right direction, but that is how far I go.
The best advice i can give is to start by doing 10-15h of proper training about JS.
Here are a paid and a free course:
https://stmforum.com/forum/showthrea...ning-for-22USD
Or find a freelancer to do it for you.