Results 1 to 6 of 6

Thread: Emergency! Random image script not working - weird! Client MAD.........

  1. #1
    Join Date
    Aug 2017

    Question Emergency! Random image script not working - weird! Client MAD.........

    Hi friends! I'm working in Dreamweaver CC and have inserted and revised a random image script on an existing page. It works great when previewing from my desktop but it does NOT work after uploading to the server. I've tried everything I could think of and can't make headway with it. The links to the images are good and they all work -- just not with the script. The client is about ready to kill me (and not with kindness). Can anyone help? I'd be ever so appreciative!!

    Here's the link to the page where I used the script: http://decoymag.com/classifieds/classifi.htm

    The image, which changes upon reload/revisit, is supposed to be appearing belong the small 'CLASSIFIEDS' header and before the paragraph text which begins with "Following is a complete list of..."

    Here's a snippet of the script that I inserted into the page - perhaps you'll see the problem right away? (Gee, I hope so!)

    <script language="JavaScript">

    Random Image Script- By JavaScript Kit (http://www.javascriptkit.com)
    Over 400+ free JavaScripts here!
    Keep this notice intact please

    function random_imglink(){
    var myimages=new Array()
    //specify random images below. You can have as many as you wish

    //specify corresponding links below
    var imagelinks=new Array()

    var ry=Math.floor(Math.random()*myimages.length)
    if (ry==0)
    document.write('<a href='+'"'+imagelinks[ry]+'"'+' target="new" ><img src="'+myimages[ry]+'" border=0></a>')

    Once again, THANK YOU MY FRIEND(S)!!!!

    -- 'ding

  2. #2
    Join Date
    Mar 2007
    document.write has been defunct for along time now, the appropriate method is to have an <img> tag that is named, you then update that element with the image source data.

    Search this forum and you will find image rotation / replacement / randomizing scripts available to hack in to your script.

    You will find alot of outdated coding methods on JavaScript Kit as well as other script depositories.

    A quick idea here
    function rndImage( i ){
        vat r = Math.floor( Math.random() * i.length ) | 0;
        return i[ r ];
    function updateTarget( ad ){
        // update the image
        var t = document.getElementById( "myImage" );
        t.src = ad.src;
        // update the link
        var a = document.getElementById( "myImageLink" );
        a.href = ad.href;
    function changeImage(){
      var img = rndImage( adverts ); 
      update( img ); // update the image...    
    adverts = [ {src:"../advertisers/RJG/RJG1.jpg", href:"http://www.rjgantiques.com},
        {src:"../advertisers/RJG/RJG2.jpg", href:"http://www.rjgantiques.com"},
        {src:"../advertisers/RJG/RJG3.jpg", href:"http://www.rjgantiques.com"},
        {src:"../advertisers/RJG/RJG4.jpg", href:"http://www.rjgantiques.com"},
        {src:"../advertisers/RJG/RJG5.jpg", href:"http://www.rjgantiques.com"},
        {src:"../advertisers/RJG/RJG6.jpg", href:"http://www.rjgantiques.com"} ];
    // set a timer to change the images every 30 seconds.

    Basically if you use an array of objects, you can store all information about that advert like the image, the links, the css, or modify the routines to hook and change alternative image elements or any special size required. I had a banner script that would modify the size of the banner to fit a set window.

    So an element {src:"../advertisers/RJG/RJG5.jpg", href:"http://www.rjgantiques.com"} could have {src:"../advertisers/RJG/RJG5.jpg", href:"http://www.rjgantiques.com", height:150, width:500} and all you would need to do is apply them to the relevant objects.

    Then in the page where you want the adver to show... put the appropriate HTML so that the script can hook and update the elements
    HTML Code:
    <a id="myImageLink" href="./"><img name="myImage" id="myImage" src=""></a>
    So I suggest you have a look at other scripts in this site.

    I would also suggest that you avoid Dreamweaver as it is very old and writes the wrong DOCTYPE as well as a load of bloat scripting that isn't needed these days, it is that which may be conflicting with other scripting, I always found it a PITA and spent more time editing out and chasing bugs because of DW than my own buggy scripting.

    I moved on to an editor that is text base, WYSIWYG is fine but you have a notepad++ install and a web browser, you have the same sort of environment, meaning you have syntax highlighting and can test immediately in your chosen web browser and web browsers are much better these days at error reporting (in the console.log F12 open / closes) and tells you what went wrong and where.
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  3. #3
    Join Date
    Aug 2017
    Hi! I have a question about these lines of code in your answer to my post:

    // set a timer to change the images every 30 seconds.

    I'm trying to have the image change (either random or sequentially) each time the page is refreshed. However, this coding seems like it's going to change according to a set time instead. Is that right? Also, I wonder how to make sure the browser displays at least one ad if the ad blocker is otherwise preventing it from being shown on the page. I discovered that when I turned off uBlock Origin, the image would load correctly and would cycle as I wanted it to. That's how it acts with the code presently, but if the ad blocker is turned on, there is no image displayng at all on the page.

    This is all so confusing!

    THANK YOU........ Karen

  4. #4
    Join Date
    Mar 2007
    If you have a set of static images, use the localStorage object to store the information between pages so that your image can refresh and not load the same image over again.

    The setInterval is an event timer that calls the function every 30 seconds as the parameters are the function as a string or as its object and the time in milliseconds.

    If you were needing different display periods, then you would add to the image data a property that is going to set the time period to call the next refresh.

    The question is are you looking to only change image on each page crefresh or are you looking for a script that shows all images in a sequence and starts again randomly on each page refresh?
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  5. #5
    Join Date
    Aug 2017
    Thank you for explaining that!!!!

    I am looking to change just one image on the page each time it's refreshed. The client has given me 5 ads and wants them to be different each time the page is visited. Honestly, just having them change on a page refresh, even if they are simply random, would be okay.

    I discovered that one of my ad blockers (uBlock Origin) was preventing the ad from appearing when I tested it. After I removed all instances of the word 'ad' in the paths and image names, the ad started to appear and even changed on the page refresh. I had originally wanted a new page to load in the browser when the ad was clicked on but my popup blockers prevented that from working. It wasn't such a big sacrifice to simply let their website load in the same window and be done with it!

    So far these changes seem to work and if the advertiser approves it, I'm ready to move on.

    I've never been able to write my own scripts and it's been years since I've even modified one. I struggle with severe memory loss and I'm generally not able to learn anything new. And once a bit of information leaves my brain, it's gone forever. As you can imagine, it's been a struggle. I can't thank you enough for your time and your help, which is especially valuable to a person like me.

    THANK YOU AGAIN.......

  6. #6
    Join Date
    Mar 2007
    First a test to see if HTML5's localStorage object is supported in your clients browser.
    function supports_html5_storage(){
        try {
            return 'localStorage' in window && window['localStorage'] !== null;
        } catch(e) {
            return false;
    (c/o www.diveintohtml5.info )

    This could be modified so that the check value is set when the page loads and JavaScript is available to the browser
    localStorageSupport = ('localStorage' in window && window['localStorage'] !== null) || false;
    If local storage is not available then I suggest another alternative is to use the URL parameter to indicate between pages what advert has been shown previously, these methods can easily be found on this site using search or to search with your fave search engine the way to achieve the goal you seek.

    So storing the chosen advert in localStorage will allow you read in on the next page load the previous advert, then in your random script, all you do is remove the element previously shown and then select at random an image to show, store that image number in the localStorage object to replace the previous value, then on page load the process is repeated.
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.14345 seconds
  • Memory Usage 2,912KB
  • Queries Executed 14 (?)
More Information
Template Usage (34):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (3)bbcode_code
  • (1)bbcode_html
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (6)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (71):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates