We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34162
    • 1 Posts
    Hi all

    phpversion 4
    linux + apache

    1) How do I include a javascript file into a new page ?

    2) How do I create a new page with a body event like

    <body onload="start()">
    ?



    start() is a javascript function defined in another file.


    I know these are stupid questions but I’m new and I wanna learn laugh

    Thx in advance laugh laugh laugh
      • 32241
      • 1,495 Posts
      If I understnad clearly of your answer, I believe you can change the template, which means you can set onload event in your body tag for your template.

      Hope that helps
        Wendy Novianto
        [font=Verdana]PT DJAMOER Technology Media
        [font=Verdana]Xituz Media
        • 33453
        • 141 Posts
        In your template (manage resources/templates).

        You will probably find something like
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml">

        <head>
        .
        .
        </head>
        <body>
        .
        .
        </body>
        </html>

        Just put a
        <script type="text/javascript" src="assets/templates/yourtemplate/scripts/yourjavascript.js"></script>

        in between the <head></head> (obviously with your own pathname)

        and add your ’onload’ to the body tag.

        If you don’t want this for every page you will have to make a duplicate of your template and use that in the places you want your script.
        • Quote from: zenmaster at Dec 19, 2005, 01:47 AM

          If you don’t want this for every page you will have to make a duplicate of your template and use that in the places you want your script.

          This might be better, just make the class function call in a snippet on the page where you want it:
          http://modxcms.com/regclientstartupscript.html

          Your javascript can itself contain the onload function for the page, you don’t need to put it in the body tag:
          http://simon.incutio.com/archive/2004/05/26/addLoadEvent
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 34162
            • 1 Posts
            thx u guys laugh

            in fact I want to run the javascript only for 1 page, not for all the webiste.

            Thx for the snippet / onload tip too laugh

            I’m gonna try right now laugh