Javascript perfect random ad code

Source: Internet
Author: User

If you need to randomly display images or links to Banner in your home page, how can you achieve this?
Below is a random display of five Banner'sCodeYou can define it yourself.
Code:

Copy code The Code is as follows: <script language = JavaScript>
VaR M = 5; // Several banners are randomly displayed.
VaR n = math. Floor (math. Random () * m + 1)
Switch (N)
{
Case 1:
Document. Write ('banner1 HTML ');
Break;
Case 2:
Document. Write ('banner2 HTML ');
Break;
Case 3:
Document. Write ('banner3 HTML ');
Break;
Case 4:
Document. Write ('banner4 HTML ');
Break;
Case 5:
Document. Write ('banner5 HTML ');
Break;
}
</SCRIPT>

What if the corresponding connections need to be added to some advertising images? The Code remains the same:

Code:
[Ctrl + A select all Note: If you need to introduce external JS, You need to refresh it to execute]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.