Jump to content

[SOLVED] Insert Javascript into HTML Box (mypresta.eu)


Recommended Posts

Hi, im doing some changes on this module HTML Box, where i can insert html code.

 

I have a sidebar banner, but the same is displayed on all the products page, i would like change this image for an image randomizer script.

 

I've found this

 

<script language="JavaScript">
<!--
 
function random_imglink(){
var myimages=new Array()
 
Rickey1.png"
 
ii1.jpg"
 
var ry=Math.floor(Math.random()*myimages.length)
if (ry==0)
ry=1
document.write('<img src="'+myimages[ry]+'" border=0>')
}
random_imglink()
//-->
</script>
 
On single HTML  works perfect, but when i include this into HTML Box, nothing happens...
 
Any idea why? or how must i insert this javascript into HTMLbox?
 
Thank you in advance for your answers.
 
Luis
Link to comment
Share on other sites

you need to remove spaces from:

 

var myimages=new Array()
 
Rickey1.png"
 
ii1.jpg"
Link to comment
Share on other sites

 

you need to remove spaces from:

 

var myimages=new Array()
 
Rickey1.png"
 
ii1.jpg"

 

 

Thanks again for your answer Vekia.

 

I did, i removed spaces and reduced the number of images, now my script for testing looks:

 

 

 

<script language="JavaScript">
<!--
 
function random_imglink(){
var myimages=new Array()
 
 
var ry=Math.floor(Math.random()*myimages.length)
if (ry==0)
ry=1
document.write('<img src="'+myimages[ry]+'" border=0>')
}
random_imglink()
//-->
</script>
 
 
But still without appear, im exactly using this script into HTMLbox... no results.... 
 
Any other idea...?
 
Thanks
Link to comment
Share on other sites

you need to use also ";" att the eand of each non-function line as it is suggested for javascript syntax

function random_imglink(){
var myimages=new Array();
 
myimages[1]="http://www.cnet.com/...end_270x337.jpg";
myimages[2]="http://www.darecipes.../images/274.jpg";
myimages[3]="http://news.cnet.com...rt7_270x337.jpg";
 
var ry=Math.floor(Math.random()*myimages.length);
if (ry==0);
ry=1;
document.write('<img src="'+myimages[ry]+'" border=0>');
}
random_imglink();
Link to comment
Share on other sites

 

you need to use also ";" att the eand of each non-function line as it is suggested for javascript syntax

function random_imglink(){
var myimages=new Array();
 
myimages[1]="http://www.cnet.com/...end_270x337.jpg";
myimages[2]="http://www.darecipes.../images/274.jpg";
myimages[3]="http://news.cnet.com...rt7_270x337.jpg";
 
var ry=Math.floor(Math.random()*myimages.length);
if (ry==0);
ry=1;
document.write('<img src="'+myimages[ry]+'" border=0>');
}
random_imglink();

Thanks for your advice but nothing happens! 

 

I dont know why the JS cant be executed ... ready to give up...

Link to comment
Share on other sites

can you show how your code looks like right now? i will test it on my own store.

 

Sure, thanks.

 

This is the code than i have into HTMLbox

 

<script language="JavaScript">
 
function random_imglink(){
var myimages=new Array();
 
 
var ry=Math.floor(Math.random()*myimages.length);
if (ry==0);
ry=1;
document.write('<img src="'+myimages[ry]+'" border=0>');
}
random_imglink();
 
</script>
Link to comment
Share on other sites

take a look here: http://demo.mypresta.eu/en/

scroll page down, right above footer.

the same module, the same code.

 

take a look on this test tool: http://codepen.io/hrbj/pen/jvqig

 

the same output

hmmmm... i see it works for you, could be a conflict with other prestashop module... could be.

 

But.. random function doesnt work, right? i mean, in every reload always show only the red banner... do you see it?

Link to comment
Share on other sites

take a look here: http://demo.mypresta.eu/en/

scroll page down, right above footer.

the same module, the same code.

 

take a look on this test tool: http://codepen.io/hrbj/pen/jvqig

 

the same output

Hi Vekia,

 

Finally works! i used another javascript and it works with your HTMLbox module. Works perfect!

 

Thank you for your constant support.

 

Best regards!

 

LuchoFox

Link to comment
Share on other sites

glad to hear that it works for you!

may i know something more about code that you're using right now? im so curious because idea about this "rotated" image banner is very good

 

 

i marked this thread as [solved]

 

with regards,

Milos

Link to comment
Share on other sites

glad to hear that it works for you!

may i know something more about code that you're using right now? im so curious because idea about this "rotated" image banner is very good

 

 

i marked this thread as [solved]

 

with regards,

Milos

 

Looks it working: http://goo.gl/pJtSmc

 

Could be a good module for a lot of people... needs a admin panel where update the images... eh?

 

Include me on your testing users when you develope it!

 

FINAL CODE:

 

<script type="text/javascript"> var images = [], index = 0; 
images[0] = "<a href = '#'><img src='http://replacethisurl.com/imagen/today.jpg' alt=''></a>"; 
images[1] = "<a href = '#'><img src='http://replacethisurl.com/imagen/today2.jpg' alt=''></a>"; 
images[2] = "<a href = '#'><img src='http://replacethisurl.com/imagen/today3.jpg' alt=''></a>"; 
images[3] = "<a href = '#'><img src='http://replacethisurl.com/imagen/today4.jpg' alt=''></a>"; 
index = Math.floor(Math.random() * images.length); 
document.write(images[index]); 
</script> 
  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...