body Xonload="javascript:something"

body Xonload="javascript:something"

by Daniele Cordella -
Number of replies: 4
Picture of Core developers Picture of Plugin developers
How can I load the body
<body Xonload="javascript:something">
instead of the standard body
<body>
into a page of a moodle module?
I only have to write a new page from scratch or does it exist a trick?
Thank you in advance.

Sorry, the X before the onload was added by the editor, not by me.
Average of ratings: -
In reply to Daniele Cordella

Re: body Xonload="javascript:something"

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Doesn't this thread from the last few days ask and answer pretty much exactly this question?
In reply to Tim Hunt

Re: body Xonload="javascript:something"

by Daniele Cordella -
Picture of Core developers Picture of Plugin developers
Ciao Tim and thanks for your reply.
I read the thread you suggested but... I believe I am looking for something different.

Maybe because of my deep incompetence but, what I understand is that by adding something like

require_js('one of the magic words');

I add libraries to the head of the page.
What I am looking for, instead, is a way to customize the body load.

<body Xonload="execute my js">.

I want to automatically submit a form written in the page.
I want to have something like:

<body Xonload="javascript:document.forms.myform.submit();">

Are they the same problem?
Thank you in advance.
In reply to Daniele Cordella

Re: body Xonload="javascript:something"

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

<body Xonload="execute my js"> is not really sensible, because if two things on the page want to do that, you are stuck.

That is why require_js(array('yui-yahoo', 'yui-event'); then YAHOO.util.Event.onDOMReady(WeekDays) in any .js file is a much better solution. Which is exactly the advice we got to by the end of the other thread.