View Full Version : Daily Quoter script
Haisook
03-31-2006, 10:45 PM
I need a daily quoter in my website (new quote everyday). I need it to be put as text in the sidebar. The "Tip of the day" script in main dynamic drive pages loads in a pop-up before the site loads. I don't like it that way actually.
Any ideas?
jscheuer1
03-31-2006, 10:49 PM
http://www.dynamicdrive.com/dynamicindex17/dowiframe2.htm
Haisook
03-31-2006, 11:00 PM
Thanks John, but..
I noticed I have to assign 31 htms beforehand. Not that this is annoying, but I'd like to put like 200 quotes to choose randomly from; In a single txt file for instance. Can that be done?
djr33
04-01-2006, 12:28 AM
html and javascript have no server access. you'd have to use serverside scripting, like php to do this. You could use a database or a text file. You might be able to use javascript, but it would be client side, and slow down the users computer.
jscheuer1
04-01-2006, 03:57 AM
Thanks John, but..
I noticed I have to assign 31 htms beforehand. Not that this is annoying, but I'd like to put like 200 quotes to choose randomly from; In a single txt file for instance. Can that be done?
I think so, you could make like an external or internal javascript. Your quotes could be in an array. A random quote could be selected from the array on each page load and be assigned as the innerHTML of a division.
Only thing is it would be random on each page load, not a daily quote, or you could have it based on the day of the year, each day would bring the next quote, in order until the end was reached, then it could start over.
I just had a had a bunch of paid work dumped in my lap but, I think I will write this idea up at some point. Shouldn't really take all that long. If I had the list of 200 quotes to work from, that would make things easier to visualize.
Also would you be most interested in a random or a daily progression?
jscheuer1
04-01-2006, 09:34 AM
OK, here's a first effort. No quotes in the quotes unless escaped -
he said,\"Hello\".
The script is pretty easy to follow:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<title>Random or Daily Quotes - Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
#quote { /*style for quote division*/
position:relative;
width:375px;
height:70px;
border:1px solid black;
font-family:sans-serif;
font-size:95%;
padding:3px;
background-color:lightyellow;
}
#auth { /*style for quote author, if any*/
position:absolute;
bottom:3px;
right:10px;
}
</style>
<script type="text/javascript">
/*///////////////////////////////
* Random or Daily Quotes Script © John Davenport Scheuer
* as first seen in http://www.dynamicdrive.com/forums
* user name jscheuer1 - This credit must remain for
* legal use. Ver Date: 4/1/2006
///////////////////////////////*/
var method=0 //Set to 1 for rotating daily, 0 for random each page load
////////////BEGIN QUOTES: (Start Editing after next line)//////////
var quotes="\
Sed ut perspiciatis unde omnis iste natus error sit voluptatem.~Plato^\
Accusantium doloremque laudantium totam rem aperiam.^\
Eaque ipsa quae ab illo inventore veritatis et quasi architecto.~Plato^\
Beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia.^\
Voluptas sit aspernatur aut odit aut fugit.~Plato^\
Sed quia consequuntur magni dolores eos qui ratione.^\
Voluptatem sequi nesciunt. Neque porro quisquam est.~Plato^\
Qui dolorem ipsum quia dolor sit amet.^\
Illegitimi Non Carborundum.~General 'Vinegar Joe' Stilwell^\
Consectetur, adipisci velit sed quia non numquam eius modi.~Plato^\
Tempora incidunt ut labore et dolore magnam aliquam quaerat.^\
Voluptatem. Ut enim ad minima veniam.~Plato^\
Quis nostrum exercitationem ullam corporis suscipit laboriosam.^\
Nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum.~Plato^\
Iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur.^\
Vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?~Socrates^\
" ///////////END QUOTES (Stop Editing)////////////
quotes=quotes.split("^")
quotes.length=quotes.length-1
if(method){
var qdate=new Date()
var qnum=Math.ceil((qdate.valueOf()-new Date(qdate.setMonth(0)).setDate(1))/(1000*60*60*24))%(quotes.length-1)
}
else
var qnum=Math.floor(quotes.length*Math.random())
</script>
</head>
<body>
<!-- Begin Body Section of Quote Script -->
<noscript><div id="quote">"Quis nostrum exercitationem ullam corporis suscipit laboriosam."<span id="auth"> ~ Plato</span></div></noscript>
<script type="text/javascript">
document.write('<div id="quote"></div>')
var quotediv=document.getElementById?document.getElementById('quote'):documet.all['quote']
quotediv.innerHTML=/~/.test(quotes[qnum])? '"'+quotes[qnum].replace(/~/, '"<span id="auth"> ~ ')+' </span>' : '"'+quotes[qnum]+'"'
</script>
<!-- End Body Section of Quote Script -->
</body>
</html>
Haisook
04-01-2006, 02:02 PM
Thanks djr33 for your reply.
John,
Oh.. your script is great! Thank you for your effort. This should be sumbitted to dynamicdrive's database I must say.
I noticed it shows a new random quote on each pageload. Still a cool effect for certain needs, but I wonder if you could make it in a daily progression..?! I just want to avoid having all the quotes read in one day!
Thanks again
Haisook
04-01-2006, 02:33 PM
Sorry I have just seen the option for daily quotes.
Thanks a lot!
jscheuer1
04-02-2006, 09:36 AM
Sorry I have just seen the option for daily quotes.
Thanks a lot!
And just this morning it stopped working! I've edited the code so that it can handle DST gracefully. If you just want to edit the line involved:
var qnum=Math.ceil((qdate.valueOf()-new Date(qdate.setMonth(0)).setDate(1))/(1000*60*60*24))%(quotes.length-1)
Don't miss the lonely ) nearer to the end of the line.
Haisook
04-02-2006, 01:11 PM
Ok, i'll edit it.. thanks, though it worked for 2 days until now without any problems.
Padwan
04-18-2010, 03:05 AM
I see these posts are from a few years ago. Just wanted to say a BIG thanks, since they are very helpful to this newbie!
zhongying
04-20-2010, 01:02 AM
Oh.. your script is great! Thank you for your effort. This should be sumbitted to dynamicdrive's database I must say.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.