473,804 Members | 2,100 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

1 New Member
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,increment s 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 2577
acoder
16,027 Recognized Expert Moderator MVP
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
1509
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: function a_message() { alert('I came from an external script! Ha, Ha, Ha!!!!'); } I am told to create an HTML page that accesses the .js script. (I did that).
5
5216
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 to wait for the external resource to load to show up the page, thus giving a perceiving faster load time for the user.
4
3183
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 executes. Help! I can't figure this out. The external JS file is "members.js". Here's the code:
4
2827
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" src="country_state.js"> </script>
3
5740
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 language="JavaScript" type="text/javascript" src=/scripts/openpopup.js></script>. What I can't seem to figure out is how to link it to the image on my page to bring up the new pop up. The code I used for the script in my page was this one...<a...
5
3655
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 contains one JavaScript function. When I add the JavaScript function using Me.Page.ClientScript.RegisterStartupScript(Page.GetType, "myFunction", stringBuilderContainingMyScript.ToString()) I am able to use my function and everything works...
4
4276
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
3625
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 Drive. I'd try to build something myself, but I just need something quick and easy. The instructions say to put all the code on the same page; the functions in the <head> and then some code to call the countdown in the <body>. In order to keep my main...
1
6026
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%>'; which would work fine if the javascript was in the .aspx file, but when
29
24431
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 main page, both worked successfully apart, but it wasn't until I combined them that I have had an issue. My aim was to have ajax add the external page into a div and then load lightbox from that div, though that is where the problem lies as I can...
0
9594
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10595
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10089
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7634
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4308
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.