Results 1 to 8 of 8

Thread: Testing javascripts

  1. #1
    Join Date
    Jun 2010

    Testing javascripts

    When I run javascripts that make big calculations in web browsers, some of them say "the script is stuck in a loop. Do you want to continue?" And I say yes, and it goes on... and after many clicks to continue, it finally prints out a result I want.

    Different browsers do different things. Some just choke, others sort of refuse to continue and even have to be force quit. I can understand that there must be some safeguards to stop people foisting absurdly long processes onto other people' computers on the internet but what about when you want to do this for yourself offline, is there any browser that can be tweaked to allow offline calculations. Not just calculations, you see, but also print outs. In browsers, it is terrific, you can use document-write to see what is going on...

    I want to be able to set a js going and leave for an hour or two or eight and come back and see a result.

    Yes, I know I maybe should use a different programming language that does not depend on browsers but I want to know if I can keep using this javascript without browsers choking (and off line). Perhaps there is a js editor that will allow printing to it without the normal browser limitations?

  2. #2
    Join Date
    Aug 2007
    Firefox allows you to set after how long should the Stop Script dialogue box appear. I'm sure that Opera and a few others have an equivalent.

    You could also try optimising your code a bit, but by the sounds of it, that will be a pretty useless solution.

  3. #3
    Join Date
    Jun 2010
    Thanks for this. Yes, I am giving it a go now. I am thinking to give it much more than the 20, more like 4000!

    Does anyone know of any facility *besides browsers* (that have so many overheads and are for internet use), that can run a js program and "print" out on-screen results?

  4. #4
    Join Date
    Aug 2007
    SpiderMonkey is behind Firefox.

    Technically, JavaScript can only be used to refer to the scripting language used by Netscape and Mozilla, because JavaScript is just one implementation of ECMAScript. A Google search for that will turn up a few other implementations. It's main use however, is as a scripting language in browsers, as well as a few other applications (e.g. Adobe PDF's programmes as far as I know).
    Last edited by Declan1991; 08-12-2010 at 07:11 AM.

  5. #5
    Join Date
    Oct 2008
    I want to be able to set a js going and leave for an hour or two or eight and come back and see a result.
    It's really not that difficult to do, just requires a re-thinking of your approach to the code. Why do you need to loop for that long of a time? What you need to do is break up whatever's happening in the loop in to manageable methods which can be updated with different data and run in a faux recursive fashion making use of setTimeout or setInterval. For an extremely simplified example:
    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
    <title>Some Title</title>
    <script type="text/javascript">
    var RECURSOR = {
        value : null,
        doCalc : function () {
            var i,
                O = this,
                el = document.getElementById('message');
            if (O.value !== null) {
                for (i = 1; i < 2001; i++) {
                    O.value += 1;
                if (O.value < 100000) {
                    el.innerHTML = O.value;
                    window.setTimeout(function () { O.doCalc(); }, 2000);
                } else {
                    el.innerHTML = 'Finished! Final result is: '+ O.value;
    window.onload = function () {
        RECURSOR.value = 0;
    <div id="message"></div>
    I could set that up to do whatever I want and let it run for days if needed. Of course this is very simple thing here, but as I say you need to re-define how your code is running to allow it to do bits and pieces and track it's own progress as such so that it can pause to avoid excessive recursion and then pick back up again after a brief cool down so to speak, resuming with the new values.

  6. #6
    Join Date
    Apr 2006
    Quote Originally Posted by patriciaaldoraz View Post
    When I run javascripts that make big calculations in web browsers, some of them say "the script is stuck in a loop....

    I want to be able to set a js going and leave for an hour or two or eight and come back and see a result....
    Try running it in an iframe.

  7. #7
    Join Date
    Jun 2010
    I sense your economy and elegance! You are way advanced from my simple efforts.

    I /had/ thought to break the task up more in manageable bits but you are saying something more subtle I think, to somehow break the calculation and make the browser reload and carry on using fed results from earlier. Wish I could work out how quite to do this.

    Suppose I wanted to search every possible way four integer variables that were not greater than about 200 could be and to identify if some relation exists between them. Sort of moron maths, different to the way Wilkins solved Fermat's last theorem (with intelligence). I know how to loop through the lot and test for a condition but how to break it up along your lines? Your example is so way above my head I cannot apply it. There! I have said it and without a drop of bourbon to give me courage.

  8. #8
    Join Date
    Feb 2009
    as the poster says.

    Divide and conquer.

    use setTimeout or setInterval.

    and maybe look at your code for efficiency. Assign variables outside loops with values and use inside loops to prevent repetitive calculation of data that doesn't change. Use of "functions" with (eg)
    function fred(a,b){
    //calcs with a & b assigned to myResult here
     return myResult;
    // &
    var bill = fred(jim,dave);
    for(etc etc).....
    in them if necessary to box-up some of the code and simplify the main body of the code.

    I did find help sites dealing with just such a subject. Go looking.

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.14008 seconds
  • Memory Usage 2,926KB
  • Queries Executed 15 (?)
More Information
Template Usage (35):
  • (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_code
  • (1)bbcode_html
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (8)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)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