Reply
Making an external JS file and calling it with <script> tags from HTML
Old 11-06-2009, 04:29 PM Making an external JS file and calling it with <script> tags from HTML
Novice Talker

Posts: 8
Trades: 0
Ok, I have a slight issue. I have the following JS & HTML code placed in my site.

The content ("This is my new Ticker!") of the code is in the HTML file, but I want this content to be placed in the JS file so I can edit the code in one place and have it linked to mulitple sites.

What script do I need or how do I do this. THANKS


Code inserted in HTML...

Quote:
<DIV ID="TICKER" STYLE="overflow:hidden; width:520px" onmouseover="TICKER_PAUSED=true" onmouseout="TICKER_PAUSED=false">
This is my new Ticker!
</DIV>
<script type="text/javascript" src="webticker_lib.js" language="javascript"></script>
External Javascript file...
Quote:


// WebTicker by Mioplanet
// www.mioplanet.com
TICKER_CONTENT = document.getElementById("TICKER").innerHTML;

TICKER_RIGHTTOLEFT = false;
TICKER_SPEED = 2;
TICKER_STYLE = "font-family:Arial; font-size:12px; color:#444444";
TICKER_PAUSED = false;
ticker_start();
function ticker_start() {
var tickerSupported = false;
TICKER_WIDTH = document.getElementById("TICKER").style.width;
var img = "<img src=ticker_space.gif width="+TICKER_WIDTH+" height=0>";
// Firefox
if (navigator.userAgent.indexOf("Firefox")!=-1 || navigator.userAgent.indexOf("Safari")!=-1) {
document.getElementById("TICKER").innerHTML = "<TABLE cellspacing='0' cellpadding='0' width='100%'><TR><TD nowrap='nowrap'>"+img+"<SPAN style='"+TICKER_STYLE+"' ID='TICKER_BODY' width='100%'>&nbsp;</SPAN>"+img+"</TD></TR></TABLE>";
tickerSupported = true;
}
// IE
if (navigator.userAgent.indexOf("MSIE")!=-1 && navigator.userAgent.indexOf("Opera")==-1) {
document.getElementById("TICKER").innerHTML = "<DIV nowrap='nowrap' style='width:100%;'>"+img+"<SPAN style='"+TICKER_STYLE+"' ID='TICKER_BODY' width='100%'></SPAN>"+img+"</DIV>";
tickerSupported = true;
}
if(!tickerSupported) document.getElementById("TICKER").outerHTML = ""; else {
document.getElementById("TICKER").scrollLeft = TICKER_RIGHTTOLEFT ? document.getElementById("TICKER").scrollWidth - document.getElementById("TICKER").offsetWidth : 0;
document.getElementById("TICKER_BODY").innerHTML = TICKER_CONTENT;
document.getElementById("TICKER").style.display="b lock";
TICKER_tick();
}
}
function TICKER_tick() {
if(!TICKER_PAUSED) document.getElementById("TICKER").scrollLeft += TICKER_SPEED * (TICKER_RIGHTTOLEFT ? -1 : 1);
if(TICKER_RIGHTTOLEFT && document.getElementById("TICKER").scrollLeft <= 0) document.getElementById("TICKER").scrollLeft = document.getElementById("TICKER").scrollWidth - document.getElementById("TICKER").offsetWidth;
if(!TICKER_RIGHTTOLEFT && document.getElementById("TICKER").scrollLeft >= document.getElementById("TICKER").scrollWidth - document.getElementById("TICKER").offsetWidth) document.getElementById("TICKER").scrollLeft = 0;
window.setTimeout("TICKER_tick()", 30);
}
StreetfireD. is offline
Reply With Quote
View Public Profile
 
 
When You Register, These Ads Go Away!
Old 11-06-2009, 06:06 PM Re: Making an external JS file and calling it with <script> tags from HTML
chrishirst's Avatar
Super Moderator

Posts: 22,214
Location: Blackpool. UK
Trades: 0
document.elementname.innerHTML = "Whatever you want to write in the element";

or

document.getElementById("TICKER").innerHTML = "Whatever you want to write in the element";
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Growing old is mandatory - Growing up is optional
Code Samples | People Counting System | Bits & Bobs
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 11-06-2009, 06:29 PM Re: Making an external JS file and calling it with <script> tags from HTML
Novice Talker

Posts: 8
Trades: 0
Does that go after... "" TICKER_CONTENT = " ?

If so.. I tried both and neither worked.
StreetfireD. is offline
Reply With Quote
View Public Profile
 
Old 11-06-2009, 06:37 PM Re: Making an external JS file and calling it with <script> tags from HTML
chrishirst's Avatar
Super Moderator

Posts: 22,214
Location: Blackpool. UK
Trades: 0
probably in one of the existing functions that write to innerHTML would be best!
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Growing old is mandatory - Growing up is optional
Code Samples | People Counting System | Bits & Bobs
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to Making an external JS file and calling it with <script> tags from HTML
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 



Page generated in 0.11842 seconds with 13 queries