First, this is a noob question as I don't know anything on web development. I'm creating a prestashop website and I have a module which display a javascript popup with a coupon code for the website, what I would like to do il to call the same script when somebody click on a specific link in another place in the main page. I searched the source code for the script and I think this is the one :
<script>
var ju_num=(typeof ju_num === 'undefined') ? '58D7493F-E32E-4ADF-AB9B-9DE26502404C' : ju_num;var asset_host='//d2j3qa5nc37287.cloudfront.net/';
(
function() {
setTimeout(
function(){
var s=document.createElement('script');
s.type='text/javascript';
s.async=true;
s.src=asset_host+'coupon_code1.js';
var x=document.getElementsByTagName('script')[0];
x.parentNode.insertBefore(s,x);},500
)
}
)()
</script>
How can I call this script on a link click ?
Thanks by advance.
EDIT :
With answer help I create a javascript file with the following :
function show_coupon() {
var a = document.getElementById("my_coupon");
a.onclick = function(){
var ju_num=(typeof ju_num === 'undefined') ? '58D7493F-E32E-4ADF-AB9B-9DE26502404C' : ju_num;
var asset_host='//d2j3qa5nc37287.cloudfront.net/';
var s=document.createElement('script');
s.type='text/javascript';
s.async=true;
s.src=asset_host+'coupon_code1.js';
var x=document.getElementsByTagName('script')[0];
x.parentNode.insertBefore(s,x);
}
return false;
}
then I loaded the javascript file in my index like this :
<script type="text/javascript" src="/js/coupon.js"></script>
and finaly I changed my link to :
<a id="my_coupon" title="" href="javascript:show_coupon()"></a>
but unfortunatly nothing happens when I click on my link.
EDIT 2 :
Ijust understood what was wrong, this script is just loading functions included in the coupon_code1.js, it was just necessary to call the right function in the link. Problem solved.