⚠️ Urgent! Active Attacks on MODX Revolution Sites Below Revolution 2.6.5
Subscribe: RSS
  • Hi,
    I am using regClientScript to add some js scripts to some (few) pages.
    This, by automatically adding the type="text/javascript" which is no longer necessary, triggers a warning when going thru html validation.

    Far from being critical, but as i would prefer to get "clean" pages, do you know where (i.e. which file i have to look into ?) can i modify regClientScript to remove this type attribute ?
    Many thanks

    PS: using Revo 2.6.5

    This question has been answered by BobRay. See the first response.

    • Does regClientScript have any chunks in your list? Often it uses a default tpl that will add the html around the output. That way we can grab that data and stick it anywhere with whatever styling we want.

      Its also possible the regClientScript script itself inserts the html, but that seems a bit strange to me. But its possible
      • Quote from: nuan88 at Sep 16, 2018, 05:53 PM
        Often it uses a default tpl that will add the html around the output.
        This would be great but i haven't seen any tpl or chunk associated with it. Believe this is a built-in function in the core files
        as it is not an extra. It's likely but i do not know Modx well enough to ascertain wether the templating of these core functions lies in different files. I 'll have to dig into the core and try to find out.

        I use it (as suggested in the Modx tutos) in a one line snippet like this :
        <?php
        return $modx->regClientScript('assets/templates/.../js/custom.js');

        and this conveniently adds a link to this customjs file (only needed on some specific pages) at the bottom of the page just above the </body>
        Thanks
        • Just found it. Below is the answer as it may be helpful to anyone facing the same issue :

          File : core/model/modx/modxclass.php line 1512

          not great to modify a core file, because of future upgrades ! but i dont know how to do it otherwise
          Perhaps the Modx team will make this modification sooner or later ??
          • discuss.answer
            I think if you add script tags around your source, RegClientScript will inject it as is. You may have to put the JS in a chunk to make it work.

            $modx->regClientScript($modx->getChunk('chunkname'));
              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
            • Hi Bob and thanks a lot for this upgrade !
              Much better than modifying a core file, which i would have forgotten on the next Modx update

              I just added a 1 line chunk "customjs" with
              <script src="assets/templates/.../js/custom.js"></script>

              used
              return $modx->regClientScript($modx->getChunk('customjs'));
              per your suggestion
              and this works like a charm !
              • I'm glad that worked. Thanks for reporting back. smiley
                  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