Click to See Complete Forum and Search --> : Scroller
vmahalin
09-30-2003, 01:28 PM
I wrote a scroller in Javascript, which seems to work when I do not add a form tag. As in, if I save code written within script tags as html the scroller starts to show up.
I wanted to extend the script by adding the following code,
<form>
<iframe id="textFile" style="display:none" onLoad="showText()"></iframe>
<input type=button value=Hello onClick="window.textFile.location = 'data.txt'">
</form>
So that I capture the contents of the text file in a Javascript variable, so that I could control the contents of the scroller by changing the contents of the file. Even if I said something like
<script>
...
...
var content = "Hello"
</script>
the code works...but when I do,
<script>
...
...
var content = "Hello"
</script>
<form>
Control variable content
</form>
..the marquee on the scroller stops ...anyone
Thanks
Use document.getElementById("textFile").location.href instead of window.textFile.location. Also, make sure your form is not named textFile.
[J]ona
vmahalin
10-01-2003, 10:10 AM
The following code in within the <Script> tag ..
<Script>
function showText(){
document.getElementById("textFile").location.href = 'data.txt'
marqueecontent= document.getElementById("textFile").innerText
}
</Script>
And the code inside form tag is
<form id="Scroller">
<iframe id="textFile" style="display:none" onLoad="showText()"> </iframe>
<input type=button value=Hello onClick="window.textFile.location = 'data.txt'">
</form>
The error I get is document.getElementById is null or not an object
What browser and version are you using?
[J]ona
vmahalin
10-01-2003, 11:59 AM
IE 6.0, I guess the code needs to be cross browser....but for the time being will be ok if I get it working in IE
Are you sure that was your error, or did it say "textFile" was undefined? IE 6.0 supports document.getElementById() as does Netscape and Mozilla. It should not give you an error, unless you are running it beforeOnLoad.
[J]ona
vmahalin
10-01-2003, 01:12 PM
Ok here is my goal,
I want the file to automatically read from a text file and display it on the scroller...........if you see the code below -
<html>
<head>
<script>
function showText(){
theText = window.textFile.document.body.innerHTML.replace(/\<[^\>]+\>/gm, "");
if(theText>"")
alert(theText);
}
</script>
</head>
<body>
<form >
<iframe id="textFile" style="display:none" onLoad="showText()"></iframe>
<input type=button value=Hello onClick="window.textFile.location = 'data.txt'">
</form>
</body>
</html>
It picks the data.txt file and alerts it. What I wish to do is perform "Window.textFile.location ='data.txt'" and then the function showText within the <script> tags and all when the onLoad of the frame kicks in automatically. How do I do it,
Secondly, what is the DOM equivalent of
theText = window.textFile.document.body.innerHTML.replace(/\<[^\>]+\>/gm, "");
Thanks
Venkat
I came up with... something... Make sure you have first.txt in the same folder (put anything you want in it, but no HTML), and data.txt in the same folder as well (again, put only plain text--no HTML). Here's what I used (note that it is not DOM compliant):
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en-US">
<head><title>JS TextFile Reading</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript"><!--
var txtFile = "first.txt";
function getVal(){
if(txtFile=="data.txt"){txtFile="first.txt";}
else{txtFile="data.txt";}
window.textFile.location.href=txtFile;
objVal = window.textFile.document.body.innerHTML;
objVal = objVal.split("<PRE>")[1];
objVal = objVal.split("</PRE>")[0];
alert(objVal);
}
//--></script>
</head>
<body>
<div onClick="getVal();"> Here <br>
<iframe id="textFile" src="first.txt"></iframe>
</div>
</body></html>
[J]ona
vmahalin
10-02-2003, 09:39 AM
Hi,
One last question, I have pasted below my whole code.......
in the populate function....when I write
alert(objScr.firstChild.innerText) or
alert(objScr.firstChild.innerhtml) ... I get nothing in the alert popup. Whereas, Iam able to popup the right results when I do something like alert(objScr.firstChild.src) etc..
I need to pass the text in the iframe to a variable inside the populate function, for the text to scroll..........in fact to the line
cross_marquee.innerHTML=marqueecontent
where marqueecontent should contain the contents of the iframe. How do I access the contents of the iframe inside the populate function.
**************************************************
<html>
<body>
<script language="JavaScript1.2">
//Specify the marquee's width (in pixels)
var marqueewidth="300px"
//Specify the marquee's height
var marqueeheight="25px"
//Specify the marquee's marquee speed (larger is faster 1-10)
var marqueespeed=2
//configure background color:
var marqueebgcolor="#DEFDD9"
//Pause marquee onMousever (0=no. 1=yes)?
var pauseit=1
//showText();
//Specify the marquee's content (don't delete <nobr> tag)
//Keep all content on ONE line, and backslash any single quotations (ie: that\'s great):
var marqueecontent='<nobr><font face="Arial"> hh </font></nobr>'
////NO NEED TO EDIT BELOW THIS LINE////////////
marqueespeed=(document.all)? marqueespeed : Math.max(1, marqueespeed-1) //slow speed down by 1 for NS
var copyspeed=marqueespeed
var pausespeed=(pauseit==0)? copyspeed: 0
var iedom=document.all||document.getElementById
if (iedom)
document.write('<span id="temp" style="visibility:hidden;position:absolute;top:-100px;left:-9000px">'+marqueecontent+'</span>')
var actualwidth=''
var cross_marquee, ns_marquee
function populate(){
var objScr = document.getElementById("Scroller")
//alert(objScr.firstChild.innerText)
if (iedom){
cross_marquee=document.getElementById? document.getElementById("iemarquee") : document.all.iemarquee
cross_marquee.style.left=parseInt(marqueewidth)+8+"px"
cross_marquee.innerHTML=marqueecontent
actualwidth=document.all? temp.offsetWidth : document.getElementById("temp").offsetWidth
}
else if (document.layers){
ns_marquee=document.ns_marquee.document.ns_marquee2
ns_marquee.left=parseInt(marqueewidth)+8
ns_marquee.document.write(marqueecontent)
ns_marquee.document.close()
actualwidth=ns_marquee.document.width
}
lefttime=setInterval("scrollmarquee()",20)
}
window.onload=populate
function scrollmarquee(){
if (iedom){
if (parseInt(cross_marquee.style.left)>(actualwidth*(-1)+8))
cross_marquee.style.left=parseInt(cross_marquee.style.left)-copyspeed+"px"
else
cross_marquee.style.left=parseInt(marqueewidth)+8+"px"
}
else if (document.layers){
if (ns_marquee.left>(actualwidth*(-1)+8))
ns_marquee.left-=copyspeed
else
ns_marquee.left=parseInt(marqueewidth)+8
}
}
if (iedom||document.layers){
with (document){
document.write('<table border="0" cellspacing="0" cellpadding="0"><td>')
if (iedom){
write('<div style="position:relative;width:'+marqueewidth+';height:'+marqueeheight+';overflow:hidden">')
write('<div style="position:absolute;width:'+marqueewidth+';height:'+marqueeheight+';background-color:'+marqueebgcolor+'" onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=marqueespeed">')
write('<div id="iemarquee" style="position:absolute;left:0px;top:0px"></div>')
write('</div></div>')
}
else if (document.layers){
write('<ilayer width='+marqueewidth+' height='+marqueeheight+' name="ns_marquee" bgColor='+marqueebgcolor+'>')
write('<layer name="ns_marquee2" left=0 top=0 onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=marqueespeed"></layer>')
write('</ilayer>')
}
document.write('</td></table>')
}
}
</script>
<form id="Scroller">
<iframe id="textFile" src="First.txt"> </iframe>
</form>
</body>
</html>
**********************************************
You would refer to the IFrame (by window.textFile.document) rather than the form.
[J]ona
vmahalin
10-02-2003, 06:53 PM
Iam sorry, I did not update the program...even after referring to the iframe instead of the form...Iam not able to access the contents of the iframe.
Put your scroller code inside of the IFrame, and just change the HTML page of the IFrame when you want to update it...
[J]ona
vmahalin
10-02-2003, 07:03 PM
Do you mean the ,
<script> tag inside <iframe> tag......iam sorry Iam not quite getting it...........
Yes, and just change the SRC of the IFrame... You can use a link with target="textFile" this way...
[J]ona
vmahalin
10-02-2003, 07:06 PM
I would like to avoid far too many messages, got the first part.....not the 2nd...can u psuedo code for me ....like a template........
thanks
It's just a concept... Not much coding really involved, basically copy & paste what you want to display as a marquee into a .html file, and display it in the IFrame. Use a link like <a href="marqueepage.html" target="textFile">text</a> to open the next page you want in the IFrame with the marquee.
[J]ona
vmahalin
10-03-2003, 09:10 AM
I do understand that you want me to replace the text file to a html file.....for the contents of the iframe...so basically changing the contents of the html will in turn get displayed in the iframe...and I can get the contents by using innerHtml....
but where will this code go..
<a href="marqueepage.html" target="textFile">text</a>
Put it where ever you want the link to go that will change the SRC of the IFrame.
[J]ona
vmahalin
10-03-2003, 11:57 AM
Thanks for the help, I thought it over and fixed it.
Thanks again
Venkat