User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 392,001 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,177 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 1230 | Replies: 4
Reply
Join Date: Oct 2006
Posts: 2
Reputation: flub is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
flub flub is offline Offline
Newbie Poster

Please help a newbie - Javascript basic

  #1  
Oct 24th, 2006
Hi All,

I wonder if any Javascript experts can help me. I have the following code on my site which create a rotating graphic in the header every time the page loads. This works great.

However what I want to do is to change the way it works slightly so that I do not have to update the code in the future.

I would like to be able to put all the image address into a text file and then for the javascript to read them from there rather than hard codeing into the web page

or

for the javascript to read all the filenames from a directory of another server?

Is this possible and can anyone help me.

Many thank in advance.




#header {
background:#476 url("http://www.blogblog.com/rounders4/bg_hdr_bot.jpg") no-repeat left bottom;
margin:0 0 0;
padding:0 0 8px;
color:#fff;
}

Basically my script works by overwriting the 'background' definition at the <body> part of the template. I wrote the following right after the <body> tag:

<script type="text/javascript">

var banner= new Array()

banner[0]="http://static.flickr.com/84/269053449_acad87a793_o.jpg"
banner[1]="http://static.flickr.com/95/269053438_4ef5a3983e_o.jpg"
banner[2]="http://static.flickr.com/96/269053404_44a3b0eda8_o.jpg"
banner[3]="http://static.flickr.com/108/269053262_608edbdda4_o.jpg"
banner[4]="http://static.flickr.com/98/269053232_6f7c6f994a_o.jpg"
var random=Math.round(4*Math.random());

document.write("<style>");
document.write("#header {");
document.write(' background:url("' + banner[random] + '") no-repeat left TOP;');
document.write(" }");
document.write("</style>");

</script>
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2005
Location: india
Posts: 143
Reputation: katarey is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 15
katarey's Avatar
katarey katarey is offline Offline
Junior Poster

Solution Re: Please help a newbie - Javascript basic

  #2  
Oct 24th, 2006
HI,

Yes this very Much possible you can use the XML file for store the URLs,
I this in one of my project

here is the solution:

For Example:http://www.katarey.com/forHelp/xml_javascript.html

make a XML file Name

img.xml
<?xml version="1.0" encoding="iso-8859-1"?>
<images>
<img>http://static.flickr.com/84/269053449_acad87a793_o.jpg</img>
<img>http://static.flickr.com/95/269053438_4ef5a3983e_o.jpg</img>
<img>http://static.flickr.com/96/269053404_44a3b0eda8_o.jpg</img>
<img>http://static.flickr.com/108/269053262_608edbdda4_o.jpg</img>
<img>http://static.flickr.com/98/269053232_6f7c6f994a_o.jpg</img>
</images>

then a html/php/asp what ever, i am using xml_javascript.html

xml_javascript.html

<script type="text/javascript">
//http://www.katarey.com
var xmlDoc=new ActiveXObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load("img.xml")
var banner= new Array()

nodes=xmlDoc.documentElement.childNodes
banner[0]= nodes.item(0).text
banner[1]= nodes.item(1).text
banner[2]= nodes.item(2).text
banner[3]= nodes.item(3).text
banner[4]= nodes.item(4).text

var random=Math.round(4*Math.random());

document.write("<style>");
document.write("#header {");
document.write(' background:url("' + banner[random] + '") no-repeat left TOP; width:740px; height:185px;');
document.write(" }");
document.write("</style>");

//Remove this Linke after testing
alert(banner[random]);
//*******************************

</script>
<body>
<div id="header"> </div>
</body>



Rahul
http://www.katarey.com
Last edited by katarey : Oct 24th, 2006 at 7:01 pm. Reason: for adding the Example
Freelance Web Designer & Developer
Http//www.Katarey.com
Reply With Quote  
Join Date: Jul 2006
Location: Deptford, London
Posts: 936
Reputation: MattEvans has a spectacular aura about MattEvans has a spectacular aura about 
Rep Power: 5
Solved Threads: 47
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Posting Shark

Re: Please help a newbie - Javascript basic

  #3  
Oct 25th, 2006
That'll only work in Internet Explorer surely? Do Netscape have an XMLDOM object equivalent? I know you can use a XMLHTTP transaction in Windows AND Netscape... but that's possibly overkill.

http://www.jibbering.com/2002/4/httprequest.html
If it only works in Internet Explorer; it doesn't work.
Reply With Quote  
Join Date: Oct 2006
Location: Utrecht, The Netherlands
Posts: 9
Reputation: BudBrocken is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
BudBrocken BudBrocken is offline Offline
Newbie Poster

Re: Please help a newbie - Javascript basic

  #4  
Oct 25th, 2006
Try this:
var xmlDoc;
if (window.ActiveXObject)
     xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
else if (document.implementation && document.implementation.createDocument)
     xmlDoc= document.implementation.createDocument("","doc",null);
Reply With Quote  
Join Date: Oct 2006
Posts: 2
Reputation: flub is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
flub flub is offline Offline
Newbie Poster

Re: Please help a newbie - Javascript basic

  #5  
Oct 25th, 2006
Thanks everyone, I will give it a try.

Many many thanks.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 10:10 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC