Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Its kinda hard to explain.....

  1. #1
    Join Date
    Aug 2006
    Posts
    235
    Thanks
    30
    Thanked 2 Times in 2 Posts

    Default Its kinda hard to explain.....

    I went on a site once and it had a bunch of HTML tutorials and codes. and one of them was when you refresh the page the pic would change. She used it for affiliates pics. and everytime you refresh the page it would change to a different one. Does anybody have that code?

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    See:

    http://www.dynamicdrive.com/forums/s...ead.php?t=8136

    I cannot vouch for the code given earlier in that thread for random images, it looked a little shaky to me but the sequential (robin) code I give later in that thread is fine. The random images thing (by Twey, in one of his weaker moments ) might be OK and if it is not, it can be easily fixed.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Hmm? That's my standard random-set code, it's perfectly sane as far as I can see. What's wrong with it?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Aug 2006
    Posts
    235
    Thanks
    30
    Thanked 2 Times in 2 Posts

    Default

    thanks so much :] but how can i make the random picture a different link as well as a different pic. like she has www.swimchick.net she has her affiliates button(pic) change when u refresh the page and the link changes with it. how would i do that?

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by Twey View Post
    Hmm? That's my standard random-set code, it's perfectly sane as far as I can see. What's wrong with it?
    I had to look again. As far as I know, document.images as you have used it in that thread requires that the image tag's name attribute correspond, not its id. IE will use either but, I think most browsers require name. I could be wrong on that though.

    //Edit:

    I just checked and it doesn't seem to matter in FF or Opera but, I think at one time it did.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by IllustriousLyts View Post
    thanks so much :] but how can i make the random picture a different link as well as a different pic. like she has www.swimchick.net she has her affiliates button(pic) change when u refresh the page and the link changes with it. how would i do that?
    You can make up a second array for the links:

    Code:
    //Set Your Images in the below Array:
    var robin_im=['files/1_side.jpg', 'files/2_side.jpg', 'files/3_side.jpg', 'files/5_side.jpg', 'files/8_side.jpg']
    //Set Your Links in the below Array:
    var robin_lnk=['http://www.google.com', 'http://www.msn.com', 'http://www.yahoo.com', 'http://www.dynamicdrive.com', 'http://www.m-w.com']
    
    //////////////// Stop Editing //////////////////
    and add in code to use it here:

    Code:
    document.write('<a href="'+robin_lnk[num]+'" target="_blank"><img src="'+robin_im[num]+'" border="0"><\/a>');
    Last edited by jscheuer1; 02-10-2007 at 05:19 PM. Reason: typo
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I just checked and it doesn't seem to matter in FF or Opera but, I think at one time it did.
    Not since IDs were introduced, I believe.
    var robin_lnk=['href://www.google.com', 'href://www.msn.com', 'href://www.yahoo.com', 'href://www.dynamicdrive.com', 'href://www.m-w.com']
    Hmm? href://? That's an odd protocol

    The equivalent adaption for my code would look something like this:
    Code:
    <a id="randomImage_link" href="http://www.google.com/">
      <img id="randomImage" src="/images/file.png">
    </a>
    
    <script type="text/javascript">
    var imgs = [
      ["/images/file.png", "http://www.google.com/"],
      ["images/myfile.jpg", "http://www.yahoo.com/"],
      ["ourfile.gif", "http://www.bbc.co.uk/"],
      ["http://www.mysite.com/theirfile.tiff", "http://www.dynamicdrive.com/"]
    ];
    
    var cimg = imgs[Math.floor(Math.random() * imgs.length)];
    document.images['randomImage'].src = cimg[0];
    document.links['randomImage_link'].href = cimg[1];
    </script>
    ... where the properties in the original HTML tags are those to use for non-Javascript browsers.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    The href in the array was a typo (I meant http there) and has been corrected in my post. I'm still not clear on when this id vs name thing with document.images changed. I'm thinking earlier NS/Mozilla browsers didn't make the switch as soon as you might think. Apparently, in modern browsers on the PC it isn't a problem. I don't know about Safari or others. It still would be being on the safe side to use name. That way even NS 4 could handle it.

    I still am not wild about one thing in your otherwise fine looking code though, Twey, the exposed variables imgs and cimg.

    Oh and you mean attributes, not properties here, right?

    where the properties in the original HTML tags are those to use for non-Javascript browsers.
    Last edited by jscheuer1; 02-10-2007 at 10:14 PM. Reason: another typo
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  9. #9
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I still am not wild about one thing in your otherwise fine looking code though, Twey, the exposed variables imgs and cimg.
    Hmm? Why? robin_im and robin_lnk are "exposed" in yours, aren't they? Or am I misunderstanding your definition of "exposed?"
    Oh and you mean attributes, not properties here, right?
    Aye.
    Apparently, in modern browsers on the PC it isn't a problem. I don't know about Safari or others. It still would be being on the safe side to use name. That way even NS 4 could handle it.
    I'm given to understand that name will soon be deprecated for images, since it serves no real purpose.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  10. #10
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I've heard some talk about that deprecation of name with images but, I think it would be a mistake somewhat along the lines of unused yet reserved words in javascript. Removing flexibility is never that good of an idea in my opinion. However, it may happen.

    By an exposed variable, I refer to a global variable. There are no global variables in my code. The one exposed object is the function itself. This is a new kick I am on but, I think it is a good one. There are so many scripts out there and so many folks using 10 or more on a page that the less that gets exposed in any given script, the better. My current pet peeve in this regard is garbage like a global:

    var ie4=document.all;

    If it means document.all, just use document.all! Or, if you must use shorthand because your fingers are falling off as you type, protect it within a/the function(s) that use it.

    I know you are rarely, if ever, guilty of this sort of flagrant invitation to variable conflict Twey.

    Some of the third party menus on DD use ie4= this and other DD scripts use ie4= that - both set globally. The two poor scripts just can't play together at all.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

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