Random image for blogger?

Hello, I need someone to help me.
I have a blog on blogger, and I want the header of my blog to be random image that change every time you refresh.
Like in this blog: http://rhy-sub.blogspot.ca/

What can I change or add to this to make the image shows randomly.

  <!--Show the image only-->
  <div id='header-inner'>
    <a expr:href='data:blog.homepageUrl' style='display: block'>
      <img expr:alt='data:title' expr:id='data:widget.instanceId + &quot;_headerimg&quot;' expr:src='data:sourceUrl' expr:width='data:width' style='display: block'/>
    </a>

I almost know nothing about HTML and JavaScribt, I couldn’t find anything helpful on the internet.

Hi there Sal,

I cannot speak for other members here, but I personally,
never work with code that has the opening body tag on
line 1639 of the document. :scream:

When I validated the page and I saw this…

[center]Fatal Error: Cannot recover after last error.
Any further errors will be ignored.
[/center]

…I headed for the hills. :mask:

coothead

4 Likes

You found the site you refer to, then find how they do.

Looking at their source code (Ctrl+u) you’ll find an embedded javascript in the place of the image. You can try replace your image <img ... /> with the same script, simplified:

<script type='text/javascript'>/*<![CDATA[*/
    var image=new Array();
        image[0]="<img alt='' src='image1.png'/>";
        image[1]="<img alt='' src='image2.png'/>";
        image[2]="<img alt='' src='image3.png'/>";
        image[3]="<img alt='' src='image4.png'/>";
    var random=Math.floor(4*Math.random());
        document.write(image[random]);
/*]]>*/</script>

Note: I have flagged this topic to move to the Javascript forum.

1 Like

Thank you very much, it really helped.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.