www.webdeveloper.com
Results 1 to 3 of 3

Thread: document.getElementById('img').src.replace(/;*/,''); not working in Chrome/Safari

  1. #1
    Join Date
    Jul 2009
    Posts
    2

    document.getElementById('img').src.replace(/;*/,''); not working in Chrome/Safari

    Below is my script that is attached to the onClick event of a bunch of product thumbnails, so that when the thumbnail is clicked, the main image changes to reflect the thumbnail product color/design.

    In order for the image swap to work, since the querystring ";jessionid=longnumber" is appended to the end of each URL when a new person visits the website, I needed to get rid of the ";jsessionid=longnumber" part. That's taken care of with the javascript replace() method in the blue lines below.

    However, the blue lines below aren't working in Chrome/Safari, although they do in IE6-8 and FF. I don't think it's because of the "replace" method because I tested out some of the use of "replace" here - http://www.w3schools.com/jsref/jsref_replace.asp - in Chrome, and had no problems.

    Code:
                function swapImage(image)
                {
    				if (document.getElementById){
    					if (image == false){
    						
    					} else {
    						document.getElementById('img').src= image;
    						var repNew = document.getElementById('img').src;
    						repNew = repNew.replace(/;.*/,'');
    						repNew = repNew.replace(/250px/g,'750px'); //replace all instances of 250px
    						repNew = repNew.replace('/Products','');
    						var test = document.getElementById('popup').href.replace(/;.*/g,'');//remove all chara after ";"
    						document.getElementById('popup').href = repNew.replace(/;.*/g,'');
    					}
    				}
                }

    Any ideas?

  2. #2
    Join Date
    Jul 2009
    Location
    Falls Church, Va.
    Posts
    780
    I have two ideas actually.

    Use the CSS method outlined here (my personal choice, very easy/fast)

    Via Javascript, put default image in a div and assign an ID to that, call a JS function to replace the div's innerHTML with new image HTML plus any other style changes. Wouldn't hurt to pre-load images also in your head area of your document.

    -jim

  3. #3
    Join Date
    Jul 2009
    Posts
    2
    Ah. I totally misspoke(or misstyped as it were) here:
    In order for the image swap to work, since the querystring ";jessionid=longnumber" is appended to the end of each URL when a new person visits the website, I needed to get rid of the ";jsessionid=longnumber" part.
    In order for the colorbox (lightbox-like popup) script to work, and correctly parse the link that the main image opens, the querystring ";jessionid=longnumber" has to be gone.

    That's why my question is more focused on removing that piece from the URL rather than on the rollover technique. Thanks though!

Thread Information

Users Browsing this Thread

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

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



Recent Articles