Results 1 to 9 of 9

Thread: Using Javascipt to count number of times a code is run

  1. #1
    Join Date
    Aug 2009

    Using Javascipt to count number of times a code is run

    Hi everyone,

    I was wondering if anybody can provide me with high level suggestions as to how to do the following in javascript.

    I want to record the number of times a piece of javascript is run across multiple disparate machines.

    To do this I was thinking that the javascript should open javascript a webpage every time it is run. I can then count how many times that webpage has been called which in turn will be the number of times the javascipt has run.

    However I don't want the webpage to open in the users machine as this will be really annoying for the user.

    Does anyone have any suggestions on how to do this? or if you can think of a better way to complete the overall goal.

    Any help would be really appreciated!!

  2. #2
    Join Date
    Jan 2008
    If you can use a server language your JS script can be placed in a PHP, ASP or CFM page where you can update a data table or set an application value. An external JavaScript file does not need to have a .js extension.

  3. #3
    Join Date
    Jan 2006
    Indiana, USA
    Are you working with a server language? If so, which one?

    You want the Javascript to load a page each time it does "something". What is the "something" it's doing? Is it launching another web page? Performing some calculation?

  4. #4
    Join Date
    Aug 2009
    Hi guys,

    Thanks so much for getting back to me. Sorry for omitting these key details in my original post.

    The javascript is sitting within a firefox extension which is comprised of just javascript.

    On right click the extension provides short cuts to a series of other web applications.

    I want to be able to track how many times the extension has been used so ie how many times has the javascript been run.

    Please let me know if more information is required here.


  5. #5
    Join Date
    Jan 2009
    You could create an invisible iframe or create a script element. Then change the src to your server-side script that counts usage.

  6. #6
    Join Date
    Aug 2009
    Thanks criterion9!

    Sorry I'm a bit of a newbie to this stuff.

    Does an I-Frame not have to still sit within an existing html page meaning that a html page would still have to be opened in the user's browser?

  7. #7
    Join Date
    Jan 2006
    Indiana, USA
    I'm sure that as soon as I post this, someone will prove me wrong, but I don't see how you can use a page as the counting mechanism as you suggest. It seems to me that the only way to do that would be to make the page do nothing but redirect to another target, in which case it functions merely as a pass-through and won't show to the user. The key there is, you have to be in the process of redirecting them to another page. It doesn't sound like that's what's happening, unless that's happening when they click on one of the links for the "other web applications". That's how it appears to me.

    There are other options, but they depend on your having access to a server side language. You must have a server involved, since you're able to serve up the counting page. If you can run a server language page there, e.g. ASP or PHP, you'd have a lot of options available to you for gathering a count. You could run an Ajax request to the page and update a counter somewhere, either in a text file, or a database.

  8. #8
    Join Date
    Jan 2009
    You can make an "invisible" iFrame by either making it 0 height and width or set it's style. An even easier solution would be to inject a script tag and set it's source to your counter server-side script. You'll just have to make sure that any output is valid javascript for that method to work.

  9. #9
    Join Date
    Jan 2009
    You could run an Ajax request to the page and update a counter somewhere, either in a text file, or a database.
    This will not be possible in this situation since most requests would be cross domain.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.17122 seconds
  • Memory Usage 2,922KB
  • Queries Executed 15 (?)
More Information
Template Usage (33):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (9)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (9)postbit
  • (9)postbit_onlinestatus
  • (9)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates