Skip to content

Instantly share code, notes, and snippets.

@crova
Last active August 14, 2018 17:33
Show Gist options
  • Save crova/e45af198630ebc13146b1f17b6149254 to your computer and use it in GitHub Desktop.
Save crova/e45af198630ebc13146b1f17b6149254 to your computer and use it in GitHub Desktop.
Image gets 'clicked' when page loads without any action
<script>
// starts to use what we got stored
var obj = getCookie();
//img swap snippet below
var img = document.querySelectorAll("img.elIMG")[1];
var img_href = document.querySelectorAll("img.elIMG")[1].dataset.imagelink;
// Starts to generate new img url based on cookie data
var new_img_href = img_href.replace(/#prod_geo#/g,obj.prod_geo).replace(/#prod_name#/g,obj.prod_name).replace(/#subprod_name#/g,obj.subprod_name).replace(/#offer_name#/g,obj.offer_name).replace(/#offer_device#/g,obj.offer_device);
// Add listener on image. Swap parameters on the image url query string if it is clicked!
function ChangeImg()
{
$(img).attr("data-imagelink",new_img_href);
}
img.addEventListener('click', ChangeImg(), false);
// button swap snippet below
var button = document.querySelectorAll("a.elButton");
var my_btn = button[0];
href = my_btn.href;
// Starts to generate new button url based on cookie data
href = href.replace(/#prod_geo#/g,obj.prod_geo).replace(/#prod_name#/g,obj.prod_name).replace(/#subprod_name#/g,obj.subprod_name).replace(/#offer_name#/g,obj.offer_name).replace(/#offer_device#/g,obj.offer_device);
// Add listener on button. Swap parameters on the button url query string if it is clicked!
function ChangeUrl()
{
$(my_btn).attr("href",href);
}
my_btn.addEventListener('click', ChangeUrl(), false);
</script>
<script>
// starts to use what we got stored
var obj = getCookie();
//img swap snippet below
var img = document.querySelectorAll("img.elIMG")[1];
var img_href = document.querySelectorAll("img.elIMG")[1].dataset.imagelink;
// Starts to generate new img url based on cookie data
var new_img_href = img_href.replace(/#prod_geo#/g,obj.prod_geo).replace(/#prod_name#/g,obj.prod_name).replace(/#subprod_name#/g,obj.subprod_name).replace(/#offer_name#/g,obj.offer_name).replace(/#offer_device#/g,obj.offer_device);
// Add listener on image. Swap parameters on the image url query string if it is clicked!
function ChangeImg()
{
$(this).attr("data-imagelink",new_img_href);
}
img.addEventListener('click', ChangeImg);
// button swap snippet below
var button = document.querySelectorAll("a.elButton");
var my_btn = button[0];
href = my_btn.href;
// Starts to generate new button url based on cookie data
href = href.replace(/#prod_geo#/g,obj.prod_geo).replace(/#prod_name#/g,obj.prod_name).replace(/#subprod_name#/g,obj.subprod_name).replace(/#offer_name#/g,obj.offer_name).replace(/#offer_device#/g,obj.offer_device);
// Add listener on button. Swap parameters on the button url query string if it is clicked!
function ChangeUrl()
{
$(this).attr("href",href);
}
my_btn.addEventListener('click', ChangeUrl);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment