473,748 Members | 11,134 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Randomize HTML

Hello

Is there a way in which I can make certain parts of Html on my website
random so that each viewer will see different material if they refresh the
page or come back onto the website later? I am currently using the
"<!--#include virtual="cgi-bin/menu1.txt" -->" command to display my menus
on every page of my site, so that the same material is shown on every page,
and I would like a way that I can randomize this perhaps.

I got a links from someone,
http://www.w3schools.com/js/tryit.as...yjs_randomlink, which
allows me to randomize links and text, but I really want to do it with
tables too as that's what I use for my menus.

Any suggestions appreciated.

_____
Gaffer
Jul 23 '05 #1
3 14634
Ron
Gaffer wrote:
Hello

Is there a way in which I can make certain parts of Html on my website
random so that each viewer will see different material if they refresh the
page or come back onto the website later? I am currently using the
"<!--#include virtual="cgi-bin/menu1.txt" -->" command to display my menus
on every page of my site, so that the same material is shown on every page,
and I would like a way that I can randomize this perhaps.

I got a links from someone,
http://www.w3schools.com/js/tryit.as...yjs_randomlink, which
allows me to randomize links and text, but I really want to do it with
tables too as that's what I use for my menus.

Any suggestions appreciated.

What do you want to randomize ? The style of the menu, or the menu
itself (each menu has different content) ? You can use javascript to
change stylesheets or classes for the menu, or if you want to change the
content of the menu, you can use an object element which can be handled
by javascript to call menu*.html instead of the invisible server-side
virtual include.
Jul 23 '05 #2

"Ron" <we*******@slid er142.com> wrote in message
news:x9******** *************** @news4.srv.hcvl ny.cv.net...
Gaffer wrote:
Hello

Is there a way in which I can make certain parts of Html on my website
random so that each viewer will see different material if they refresh thepage or come back onto the website later? I am currently using the
"<!--#include virtual="cgi-bin/menu1.txt" -->" command to display my menuson every page of my site, so that the same material is shown on every page,and I would like a way that I can randomize this perhaps.

I got a links from someone,
http://www.w3schools.com/js/tryit.as...yjs_randomlink, which
allows me to randomize links and text, but I really want to do it with
tables too as that's what I use for my menus.

Any suggestions appreciated.

What do you want to randomize ? The style of the menu, or the menu
itself (each menu has different content) ? You can use javascript to
change stylesheets or classes for the menu, or if you want to change the
content of the menu, you can use an object element which can be handled
by javascript to call menu*.html instead of the invisible server-side
virtual include.


Hello

I want to randomize a menu which contains tables with image links
(advertisements ) inside them. I want the link image to change when refreshed
so that it's new content that a user might not have seen previously. I'm
relatively new to JS so could you please explain more about how I could do
this. Incase you don't already know, I am using .asp pages for my site.

_____
Gaffer
Jul 23 '05 #3
Ron
Gaffer wrote:
Hello

I want to randomize a menu which contains tables with image links
(advertisement s) inside them. I want the link image to change when refreshed
so that it's new content that a user might not have seen previously. I'm
relatively new to JS so could you please explain more about how I could do
this. Incase you don't already know, I am using .asp pages for my site.

_____
Gaffer

Heya Gaffer,
Okay. If there's not aready some simple container for the menu, wrap the
server-side include in a span or div element with a unique ID:

<div id="menu1">
<!--#include virtual "cgi-bin/menu1.txt" -->
</div>

For simplicity, we'll keep the javascript off the page in a text file
with a .js extension, such as myScript.js. The text file should have the
following content:

function randomizeMenuAd s(menuId, numOfImages) {
numOfImages++;
if(document.get ElementById(men uId)!=null) {
var myMenuImages =
document.getEle mentById(menuId ).getElementsBy TagName("img");
for(i=0;i<myMen uImages.length; i++) {
var randImageNumber = Math.floor(numO fImages*Math.ra ndom()); //
the range of random() is [0,1)
myMenuImages[i].src = "myImageDirecto ry/menuImage" +
randImageNumber .toString() + ".jpg";
}
}
}

Consecutively number your menu images and name them with the same
prefix, ie. above we have a subdirectory called "myImageDirecto ry" that
is filled with files of the form menuImage0.jpg, menuImage1.jpg, etc.
Note that the directory is relative to the location of the page the
script is run on, not the location of the javascript file. Also note
that I assumed that all the images inside the #menu1 div were randomized
images. If not, use some other HTML element to surround only the images
to be randomized within menu1.txt and set that element's "id" attribute
to "menu1" (removing the surrounding div and ID we used before). Include
the function in the head of the webpage using a script element "<script
type="text/javascript" src="myScript.j s"></script>". Next we call the
function on every page load using "<body
onload="randomi zeMenuAds('menu 1', 10)">" if the amount of images you
have is 11 since we're numbering from 0. It is also a good idea to drop
the tag "<meta http-equiv="Content-Script-Type"
content="text/javascript" />" into the head element of the page that is
going to be using intrinsic events like onload.
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
1898
by: knoak | last post by:
Hi there, I have i site with photo-albums on it. to create a new album all i do is create a new folder. I use the following code. My only question is, how can i randomize the output, so the order of the folders is different every time? ++++++++++++++++++++++++++++++++++++++++++++++++++++
21
4178
by: Jeff Thies | last post by:
I'd like to randomly sort an array. A good method?
6
3868
by: ashu | last post by:
can any one tell me that is there any way to get a randomize (genuine) character like integer. for integer, we use random function. & for character, we use ????
2
2487
by: Rich | last post by:
Here is what I am trying for randomizing 2 numbers in the same subroutine so that they are not equal to each other: Dim j As Integer, k As Integer j = New System.Random().Next(0, 10) k = New System.Random().Next(0, 10) But j and k are always equal to each other. So I through in Randomize( ) but that did not help. Is it possible to randomize 2 different numbers in the same sub so that they are not equal to each other? How to do this?
4
2228
by: Arnold | last post by:
Hi there, Here's the situation--there is a text field in a form in which students will key in data. On the keypress event, I'd like for different sounds to be played for each character typed, either randomly or in a loop (I have a number of small, cool, computer-like sounds). I can get one sound to play for the keypress event, but don't know how to play multiple sounds. Here's the codes for playing one sound...
1
3767
by: Badass Scotsman | last post by:
Hello, This code is supposed to generate a random string each run, however I have had it live on a few sites, and it seems to create repeat strings all over the place. ------------------------------------------------------------- <% FUNCTION GetRandomCode(randomcode,codelength,numberofcombinations) codecharacters = 35
6
2402
by: mrtaka79 | last post by:
Okay, first of all, I'm a complete noob, so go easy on me. I have this code that works perfectly for me. The only thing I want to add is to randomize the pictures/links that show up. Can anyone just tell me where to add additional code to the following? BTW this is the only code I could find that works in my Beta Blogger sidebar. <a href="javascript:gotoshow()"><img border="0" width="300" src="/OneMissedCall1.jpg" name="slide"...
1
2161
by: VBSTUDENT | last post by:
I am just wondering if there is a way to randomize the aritmetic operators in code, I know how to randomize numbers but I am not sure if it is possible to randomize operators. Any help would be appreciated Thanks
5
2898
by: gggram2000 | last post by:
Hi, I'ved spent two full days trying to find a solution, I can randomize numbers between two ranges and it works fine, But my problem is when i want to randomize five numbers that I got. eg. I randomize 1-100 and I get 50. I randomize 1-900 on another input field and I get 578. I randomize 2-56 and get 31. " " and get 43. " " and get 78. So I have five numbers: 50, 578, 31, 43 and 78.
0
8989
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8828
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9367
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9319
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9243
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4599
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4869
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2213
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.