R
Richard Speiss
I am trying to display a random background image for a webpage. I found
this code to do it
<%
'Defines the number of background images you have
Const NUMBER_OF_IMAGES = 2
'Initiates the randomize function
Randomize
'Sets a variable: this will be used to hold the
'random generated value
Dim intImageNumber
'This is where we create the random number
intImageNumber = Int((NUMBER_OF_IMAGES * Rnd) + 1)
%>
Modify the body tag to accept the random number. In this case we are going
to place it within the image so as to facilitate the selection of a random
image.
<BODY BACKGROUND="bg_<%= intImageNumber %>.gif">
This did work.
In my case, I have an external style sheet with this defined:
body {
color:#333;
background-color: gray;
background-image: url(../images/bg_<%=intImageNumber%>.JPG);
background-attachment: fixed;
margin:20px;
padding:0px;
font:11px verdana, arial, helvetica, sans-serif;
}
and it is included in my main page with
<head>
<style type="text/css" media="screen">@import "css/cvs.asp";</style>
</head>
which comes after the above randomizing script
I removed <BODY BACKGROUND="bg_<%= intImageNumber %>.gif"> from the main
page and replaced it with just <body> thinking that since it is defined in
the external CSS file I wouldn't need it on each page.
I just got a gray background. Since I am really new to ASP and CSS I am not
sure the variables are global throughout included files or not. I wanted to
have the background image defined in the style file since it is used
everywhere so rather than modiying <body> for each page I could have it in
one place.
Can this be done this way? Is there a better way to handle this situation?
Many thanks
Richard Speiss
this code to do it
<%
'Defines the number of background images you have
Const NUMBER_OF_IMAGES = 2
'Initiates the randomize function
Randomize
'Sets a variable: this will be used to hold the
'random generated value
Dim intImageNumber
'This is where we create the random number
intImageNumber = Int((NUMBER_OF_IMAGES * Rnd) + 1)
%>
Modify the body tag to accept the random number. In this case we are going
to place it within the image so as to facilitate the selection of a random
image.
<BODY BACKGROUND="bg_<%= intImageNumber %>.gif">
This did work.
In my case, I have an external style sheet with this defined:
body {
color:#333;
background-color: gray;
background-image: url(../images/bg_<%=intImageNumber%>.JPG);
background-attachment: fixed;
margin:20px;
padding:0px;
font:11px verdana, arial, helvetica, sans-serif;
}
and it is included in my main page with
<head>
<style type="text/css" media="screen">@import "css/cvs.asp";</style>
</head>
which comes after the above randomizing script
I removed <BODY BACKGROUND="bg_<%= intImageNumber %>.gif"> from the main
page and replaced it with just <body> thinking that since it is defined in
the external CSS file I wouldn't need it on each page.
I just got a gray background. Since I am really new to ASP and CSS I am not
sure the variables are global throughout included files or not. I wanted to
have the background image defined in the style file since it is used
everywhere so rather than modiying <body> for each page I could have it in
one place.
Can this be done this way? Is there a better way to handle this situation?
Many thanks
Richard Speiss