Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Loading a random picture
Old 07-21-2007, 02:16 PM Loading a random picture
Experienced Talker

Posts: 44
Name: English Hentai Team
Trades: 0
My website has an header. A field of the header has an image. What I'm trying to do is that the image displayed there varies. That is, the image there would rotate (or maybe be random) from a serie of other images (all the images would have the same size).

I know there's a lot of stuff like this already done. Can someone give me a link to a script that does this (but that's easy to understand and, most of all, is very fast to load).

Thanks.
__________________

Please login or register to view this content. Registration is FREE
ehentai is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-22-2007, 04:06 PM Re: Loading a random picture
Guerrilla's Avatar
Ultra Talker

Posts: 424
Trades: -1
http://www.google.co.uk/search?hl=en...e+Search&meta=
__________________
Endless Loop: n., see Loop, Endless.
Loop, Endless: n., see Endless Loop.
Guerrilla is offline
Reply With Quote
View Public Profile
 
Old 07-22-2007, 04:29 PM Re: Loading a random picture
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
HTML Code:
<html>
  <head>
    <title>testing...</title>
  </head>
  <body>
    <script type="text/javascript">
    var aryImg=new Array("/img/img1.jpg", "/img/img2.jpg", "/img/img3.jpg");
    var rdm=Math.floor(Math.random()*aryImg.length)
    document.write('<img src="'+aryImg[rdm]+'" border="0" width="100" height="100" alt="'+aryImg[rdm]+'"/>');
    </script>
  </body>
</html>

Adapt aryImg with the images you want to randomize, and the img tag outputted options, and you should be ok
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 07-24-2007, 07:38 AM Re: Loading a random picture
Experienced Talker

Posts: 44
Name: English Hentai Team
Trades: 0
Many thanks, I thought it would be something like that...
Just a question, if someone is seeing the webpage with Javascript disabled (like the Adblock add-on for Firefox), nothing will appear in the place a random picture should be, right?

Is there a way to make a default image appear to those without Javascript enabled?
If possible, I would like that picture to be loaded only by them (so that a person that has Javascript enabled won't need to load two pictuires).

Thanks
__________________

Please login or register to view this content. Registration is FREE

Last edited by ehentai; 07-24-2007 at 07:43 AM..
ehentai is offline
Reply With Quote
View Public Profile
 
Old 07-24-2007, 08:09 AM Re: Loading a random picture
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Simply add a <noscript> after the script tag.
HTML Code:
<html>
  <head>
    <title>testing...</title>
  </head>
  <body>
    <script type="text/javascript">
    var aryImg=new Array("/img/img1.jpg", "/img/img2.jpg", "/img/img3.jpg");
    var rdm=Math.floor(Math.random()*aryImg.length)
    document.write('<img src="'+aryImg[rdm]+'" border="0" width="100" height="100" alt="'+aryImg[rdm]+'"/>');
    </script>
    <noscript>
      <img src="/img/default.jpg" border="0" width="100" height="100" alt="default"/>
    </noscript>
  </body>
</html>
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 07-24-2007, 10:17 AM Re: Loading a random picture
Experienced Talker

Posts: 44
Name: English Hentai Team
Trades: 0
Quote:
Originally Posted by tripy View Post
Simply add a <noscript> after the script tag.
...But what's inside the <noscript> tag will be loadd even if someone can see Javascript, am I wrong?
Or if someone can see Javascript, what's inside the <noscript> won't be launched?

Thanks.
__________________

Please login or register to view this content. Registration is FREE
ehentai is offline
Reply With Quote
View Public Profile
 
Old 07-24-2007, 10:32 AM Re: Loading a random picture
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
No, the noscript is interpreted only when a browser have no javascript support or the javascript is disabled
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 07-25-2007, 05:14 AM Re: Loading a random picture
Experienced Talker

Posts: 44
Name: English Hentai Team
Trades: 0
Quote:
Originally Posted by tripy View Post
No, the noscript is interpreted only when a browser have no javascript support or the javascript is disabled
Wow, that's really clever

Another question: I know a bit of Java and compilers but nothing of Javascript...
I mean, I intend to make the array of images with around 40 of them. But the browser will always have to build the array first, right? Into memory... so that means that the bigger the array, the longer it will take to complete the execution of the script, am I right?
__________________

Please login or register to view this content. Registration is FREE
ehentai is offline
Reply With Quote
View Public Profile
 
Old 07-25-2007, 05:28 AM Re: Loading a random picture
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Yep, that's right.
But don't worry for a 40 cells vector, that won't take that long to be loaded.

Javascript being a scripted language, it's a necessary phase.
Beside, just for the records, javascript have nothing related to java.
It's just the name that Netscape team decided to give it at the time where Java was really the "hot thing" to grab more attention to the product.
http://en.wikipedia.org/wiki/Javascr...ory_and_naming
Quote:
JavaScript was originally developed by Brendan Eich of Netscape under the name Mocha, later LiveScript, and finally renamed to JavaScript. The change of name from LiveScript to JavaScript roughly coincided with Netscape adding support for Java technology in its Netscape Navigator web browser. JavaScript was first introduced and deployed in the Netscape browser version 2.0B3 in December of 1995. The naming has caused confusion, giving the impression that the language is a spinoff of Java, which is not the case; and has been characterized by many as a marketing ploy by Netscape to give JavaScript the cachet of what was then the hot new web-programming language. [1] [2]
They have realised something there is close for the syntaxic part, but that's all.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Reply     « Reply to Loading a random picture
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.28686 seconds with 12 queries