-
February 7th, 2004, 07:38 PM
#1
Java/script Random HTML loader?
I am trying with little luck to find a snippet, or write one for that matter. All it needs to do is look into a specified folder for the random.txt. Javascript is prefered. I can do this with just pictures, links, and txt.
I am trying to allow it to pull a section out of a txt file written in the html format like:
<center>
<img src="images/pic.gif>
<p>
<a href="index.html">
Click here for details
</a>
</center>
just a few lines for each entry.
seperated by a blank line perhaps or a determined set of characters like &*& of something
It will pull this and place it into the <body> of a file
Does this make sense?
Thanks in advance
be safe and stay free
Your heart was talking, not your mind.
-Tiger Shark
-
February 8th, 2004, 04:54 AM
#2
I am not understanding.. Please explain a little more and I might be able to help
[shadow]l3aDmOnKeY[/shadow]
-
February 8th, 2004, 05:33 AM
#3
What you should do instead is have the random.txt file be a random.js and have the index.html link to it as a remote JavaScript. random.js will be the JavaScript in question. Having it load the file any other way isn't easily doable, so it is much better for our time to have the JavaScript contain the entries.
I'm going to a dance tonight so I don't have the time to code it.
Anyone who wants to: He wants a random.js so that he can put in an array of links, and the JavaScript would spit up the link, or just display an element from the array randomly. That is probably the simplest way to do it.
I hope someone can help you. Although in Code Review you should at least try to produce some code, post it, and ask why it doesn't work and we could critique your coding and post a better way to do it... Less guess work of what you want when we have something infront of us
-
February 8th, 2004, 04:22 PM
#4
Okay no problem.
This is what I have been using
I can use varying size and speed in this script. However it is cumbersome to edit this script on every page it is used on. So what I am asking is this. Does anybody have a working example of a javascript for example, that will do the same thing. But, pull it's content from a predetermined folder/*.txt . So instead of editing 20 scripts, I can just change the content location. Make sense now?
<script type="text/javascript">
if (document.all || document.getElementById){ //if IE4 or NS6+
document.write('<style type="text/css">\n')
document.write('.dyncontent{display: none; width: 125px; height: 125px;}\n')
document.write('</style>')
}
var curcontentindex=0
var messages=new Array()
function getElementByClass(classname){
var inc=0
var alltags=document.all? document.all : document.getElementsByTagName("*")
for (i=0; i<alltags.length; i++){
if (alltags[i].className==classname)
messages[inc++]=alltags[i]
}
}
function rotatecontent(){
//get current message index (to show it):
curcontentindex=(curcontentindex<messages.length-1)? curcontentindex+1 : 0
//get previous message index (to hide it):
prevcontentindex=(curcontentindex==0)? messages.length-1 : curcontentindex-1
messages[prevcontentindex].style.display="none" //hide previous message
messages[curcontentindex].style.display="block" //show current message
}
window.onload=function(){
if (document.all || document.getElementById){
getElementByClass("dyncontent")
setInterval("rotatecontent()", 2000)
}
}
</script>
Rotating Links and Images
<div class="dyncontent" style="display: block"><center><img src="images/ducttape.gif"><br><a href="catalog.html">More details</a></div>
<div class="dyncontent"><center><img src="images/Smiley.gif"><br><a href="portfolio.html">Our Projects</a></div>
<div class="dyncontent"><center><img src="images/corperate.gif"><br><a href="forum.html">Insert ideas here</a></div>
Thanks to all in advance.
Be safe and stay free
-
February 8th, 2004, 09:59 PM
#5
dopeydadwarf - Save that current code as something like "rotate.js". That file will be the one file with the JavaScript. In the current file(s) you should edit them so that it goes "<script language="JavaScript" src="rotate.js"></script>". This will have it so that file will look at the rotate.js file for updates and use the code in it. Do the same for all of your other files, and it should work, with each page using the exact same code so one change to rotate.js will update all of the pages.
Good luck, and it should work. It is much better than having to reprogram this entire thing for you, so thanks for showing the code for what you wanted to do.
-
February 9th, 2004, 05:33 AM
#6
Thanks Tim_axe. I work on it over the next few days. I'll post my success if applicable. If I have any problem's I'll just comeback and ask.
Thanks again
Your heart was talking, not your mind.
-Tiger Shark
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|