We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38181 ☆ A M B ☆
    • 26 Posts
    Ok ... I am honing on a problem with my configuration and all indications point to JS not being executed correctly.

    I have created a simple piece of JS (just does a popup and defines a class) called tesfile.js

    So then:

    1. I have code in a php file that registers a clientstartupscript, having checked the file exists as follows:

    if (!file_exists($doodles->config['jsUrl'].'mgr/testfile.js'))
    {
    return 'File not found at: '.$doodles->config['jsUrl'].'mgr/tesfile.js';
    }
    $modx->regClientStartupScript($doodles->config['jsUrl'].'mgr/testfile.js');

    2. When I look at the resulting generated HTML, my code includes the reference to my test file as follows:

    <script type="text/javascript" src="/home/timbutte/public_html/SponsorFinder/assets/components/doodles/js/mgr/testfile.js?v=207pl"></script>

    3. But no popup is displayed (from testfile.js) and if I try to declare a javascript variable using the class from testfile.js, it does not know about the class.

    4. If I create a simple HTML file and include JS pointing to the SAME directory and testfile.js, it executes fine, so the file is available to the web and permissions are fine.

    So why is my included JS file not being executed?

    All help gratefully received!

    Tim
      • 38181 ☆ A M B ☆
      • 26 Posts
      Resulting HTML should read ....

      <script type="text/javascript" src="/home/timbutte/public_html/SponsorFinder/assets/components/doodles/js/mgr/testfile.js?v=207pl"></script>
      
        • 9207 ☆ A M B ☆
        • 2,475 Posts
        Is your server perchance running suhosin? For "security reasons", that can end up clipping JS files. See this page: http://rtfm.modx.com/display/revolution20/MODX+and+Suhosin

        There are a couple system settings that affect the behavior of how javascript is included. You may want to check on the settings that related to JS compression... try turning them off and see if that changes the behavior.
          • 3749
          • 24,544 Posts
          Timothy, when I have trouble with the regClient*() functions, it usually turns out to be a bad template that is either missing a DOCTYPE or has incorrect HTML.

            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 38181 ☆ A M B ☆
            • 26 Posts
            OK .... solved - Phew ---

            It seems (for whatever reason?) that if I set the full path to the JS files (i.e. from the root of my LINUX machine), it does not work; change the path to be relative to the current directory, the JS runs.

            Hmmm .... must be some form of permissions re: my Apache instance/setup .... but hey it is now working.

            On with business!!
              • 9207 ☆ A M B ☆
              • 2,475 Posts
              Hmm... the src attribute for your javascript tag should use the URL of the javascript, not the full path. Javascript can't read filesystem info from your server, it MUST utilize a publicly available URL path to your asset. In other words,

              <script type="text/javascript" src="/home/timbutte/public_html/SponsorFinder/assets/components/doodles/js/mgr/testfile.js"></script>


              Shouldn't work at all. The following should work (Sorry, the forum is being troublesome here and trying to format stuff that I don't want formatted):

              src="http:// yoursite.com/assets/components/doodles/js/mgr/testfile.js?v=207pl"


              Or as you pointed out, the relative path would work too because it infers the URL:

              src="/assets/components/doodles/js/mgr/testfile.js?v=207pl"
                • 3749
                • 24,544 Posts
                Confusing paths with URLs is a mistake I can't seem to quit making. I do it less often over time, but I still do it. wink
                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting