473,396 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to Insert a counter call in external Javascript (innerHTML)?

Hello,

I actually use a counter on a webpage (This is an external script that reads and increments a value - It actually works)
To do it, I use an inline javascript but I would like to unify the entire page and call that counter directly in the external Javascript that manages the whole site.

Here's the actual code...
Expand|Select|Wrap|Line Numbers
  1. HTML
  2. <body onLoad=gen_hits()>
  3. ...
  4. <span id='hits'></span><SCRIPT language="JavaScript" SRC="http://www.mycompany.com/cgi-bin/counterdir/otherdir/counter"></SCRIPT>
  5. ...
  6. </body>
  7.  
  8. EXTERNAL JAVASCRIPT (ini.js)
  9. var hits="HITS ";
  10.  
  11. function gen_hits() {
  12. document.getElementById("hits").innerHTML=hits;
  13. }
  14.  
and here an "idea" of my request...
Expand|Select|Wrap|Line Numbers
  1. HTML
  2. <body onLoad=gen_hits()>
  3. ...
  4. <span id='hits'></span>
  5. ...
  6. </body>
  7.  
  8. EXTERNAL JAVASCRIPT
  9. var hits="HITS " + <SCRIPT language="JavaScript" SRC="http://www.mycompany.com/cgi-bin/counterdir/otherdir/counter"></SCRIPT>;
  10.  
  11. function gen_hits() {
  12. document.getElementById("hits").innerHTML=hits;
  13. }
  14.  
I also tried a piece of code using this method...
Expand|Select|Wrap|Line Numbers
  1.         function setInnerHTMLAndExecScript (element, html) {
  2.                         var newElement = element.cloneNode(false);
  3.                         newElement.innerHTML = html;
  4.                         element.parentNode.replaceChild(newElement, element);
  5.  
  6.                 }
  7.  
  8.         function gen_hits() {
  9.  
  10.                 var myHtml = '<script type="text\/javascript" SRC="http://www.mycompany.com/cgi-bin/counterdir/otherdir/counter"><\/script>';
  11.                 myHtml.type = 'text/javascript';
  12.                 setInnerHTMLAndExecScript(document.getElementById('hits'),myHtml);
  13.         }
  14.  
That works partially: in IE there's no result and in Firefox it finds,increments and displays the value but then it's impossible to continue using the page, it seems never finishing loading, even reload or refresh don't work, just close the webpage and open a new one is possible.

I asked a lot of people but no one seems to find a solution.
Does someone have an idea on how to proceed ?

Thanks in advance...
Gino
Mar 7 '11 #1
1 2552
acoder
16,027 Expert Mod 8TB
Does the external counter script output a value or does it set a value to a variable?

You can dynamically add a script to the head of the document by getting the head element and appendChild to append it to the head.
Mar 9 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Chuck Mendell | last post by:
I am having problem with external javascripts. My OS is XP Pro. I am told to create an external javascript using a .js extension. (I did that) The external .js is very simple, containing: ...
5
by: joaopedrogoncalves | last post by:
Hi, I want to load an external javascript file, get its results and stick them inside a <div> block. I also want to do this in several places on a web page. This way the browser doesn't have...
4
by: dennise9 | last post by:
My exeternal JS works fine when the call is placed in the page head or body. But if I call the same javascript from a (clicked) text link on the page, the script throws a JS error when it...
4
by: Adam Smith | last post by:
Hello, How can I call or trigger an external javascript twice in a form? I have <script language="JavaScript" src="country_state.js" name="Country_State"> <script type="text/javascript"...
3
by: stefcw | last post by:
I want to be able to bring up a pop up window in another browser using an image link. I did this when I put the script in the body. I have my external javascript file and have the call code...<script...
5
by: lilOlMe | last post by:
I have an extern JavaScript file I've called "Utils.js". It will eventually hold all of the common JavaScript functions used throughout the ASPX pages that make up my website. Right now this file...
4
by: shotokan99 | last post by:
hi, usually if we call external js file by declaring them in our html page head section: <head> .. .. .. <script language="JavaScript" src="j1.js"></script>
5
by: nickarnold | last post by:
Hi, this is my first time posting a question, so I apologize if I goof up or do not provide enough information. I am trying to implement a simple countdown script that I grabbed from Dynamic...
1
by: MarkShoe | last post by:
Hi, I have an aspx with a control on it, lets call it myControl, and I have an external javascript file. In the external javascript file, I have var myControlId = '<%=myControl.ClientID%>';...
29
by: FreshRob | last post by:
I have been trying to fix this issue the whole of today and have gotten no where. I am developing a new website, and wanted it to display a webpage in lightbox and have an external page added to the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.