Inserting Javascript code in pages

Inserting Javascript code in pages

by Luis Rodero -
Number of replies: 15

I have tried to insert Javascript code in a lesson page (for example, for launching with a link a resource page from lesson page) but editor altered code and no works. ¿Anyone knows a solution for this problem?

Thanks

Average of ratings: -
In reply to Luis Rodero

Re: Inserting Javascript code in pages

by Ray Kingdon -
Yes, the editor does sometimes know "best" smile. What functionality were you looking for. It's probably best implemented in the Lesson module itself rather than troublesome Javascript. The less Javascript is used the better really.
In reply to Ray Kingdon

Re: Inserting Javascript code in pages

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Hi Ray,
> "It's probably best implemented in the Lesson module itself rather than troublesome Javascript. The less Javascript is used the better really."

Cannot agree with you here, Ray, sorry. If a teacher wants to use Javascript for achieving a functionality which they deem necessary and has not been implemented in Moodle, why on earth should they be banned from doing so? I thought this was "open" and "free" softwarewink.

Hay, Luis, Tan, Daniel and the others, let's start a campain to liberate the use of Javascript in Moodle, shall we?

Josephblack eye

PS1 I am aware of security problems which could arise from uncontrolled Javascript
PS2 I am aware that an admin can authorize Javascript site-wide (but what if they don't want to?) see this thread
In reply to Joseph Rézeau

Re: Inserting Javascript code in pages

by Michael Penney -
Well, if a teacher is using their own install for only their own courses, then they can enable javascript and risk the consequences of a compromised server and increased support time in helping students who's browser handles javascript differently.

However, if the installation is running multiple courses, then I don't think it would be responsible for the admin to enable something for one teacher that could cause problems for other teachers.  It seems to me that if you need to rely on a central LMS server, you are doing it so you don't have to worry about issues like security, and if you can run your own LMS server, then you can disable security features (though that may be illegal in some statessmile.

I do think it is better to implement new features in a secure and planned fashion, it is open and free software, however someone has to answer questions about why such and such isn't working or how so and so got into the database. If you are asking someone else to play that role, then you may have to follow their rules.

If you know how to program then why not add the features you want into lesson as options? If they follow the Moodle API and don't cause security problems, we'll most likely be happy to include them in lesson, so long as you help with questions about how to use themsmile> .

In reply to Michael Penney

Re: Inserting Javascript code in pages

by Petr Skoda -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers
Hi!

Teachers are allowed to add Javascript, Flash, Java and SVG only in places where students can not post (Resources, Books, activity descriptions, Lessons?, etc.). All public area where students might post must be cleared before display (Forums, Chats, Wikis).

Teacher accounts should be given to trusted people only. I do not recommed public "teacher's playgrounds" on production servers. The ultimate protection for admins is to disable Flash+Javascript+Java in their browsers.

IMO there is a bug in Lesson code - it should not remove any tags. Lesson content is cleaned before storage and before display. The right way should be only format content without the cleaning.

skodak
In reply to Petr Skoda

Re: Inserting Javascript code in pages

by Mark Nielsen -
I guess I went a little too far when you told me to secure lesson and remove any XSS vulnerabilities.

I removed param cleaning and added noclean to format_text calls for page contents and answers and responses for page answers (teacher only stuff).  This will fix the javascript problems that were being discussed in this thread.

These changes are in lesson 1.6 dev.  The changes are rather extensive and so I'm hesitant to move them to 1.5 Stable (in fear of making it unstable wink).

Cheers,
Mark
In reply to Mark Nielsen

Re: Inserting Javascript code in pages

by Petr Skoda -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers
Better more cleaning then less wink
If you send me a patch for lates 1.5.2+ I can review it.

skodak
In reply to Petr Skoda

Re: Inserting Javascript code in pages

by Mark Nielsen -
I have my hands tied at work right now, but I'll try to send you something as soon as I'm able.

Cheers,
Mark
In reply to Luis Rodero

Re: Inserting Javascript code in pages

by Daniel Costa -
Hello,

I want to use javascript, too. I would like to put a link for a popup window withoult the buttons and status bar, etc... so the solution from the editor isn't the best for me. Somebody know how to insert javascripts on a lesson?

Thank's
In reply to Daniel Costa

Re: Inserting Javascript code in pages

by Peter Lawson -

Hi not sure if this will help

I used javascript to popup a fullscreen window for my flash presentation. I first built a standard pair of html pages on my desktop. one has the script in the head of the document and a scipt link in the body. the other is the pae that plays the flash presentation with a standard form with a close window button.

Once these were working on my desktop I logged into moodle and opened the html editer at the location I wanted. I wrote what I wanted to see and then switched to html view using the <> button.

I pasted the scripted link in the body at the appropriate place.

Problem with this htmnl editor is tht you dont have a head section so I copied the head section with its script and pasted it into the editor in one piece at the top.

Saved and closed and off it went no probs.

Moodle seems to change the script and makes the head invisible again but s long as you dont try and edit that again it seems to work fine.

If you decide to edit the page then you will have to replace the link script getting rid of what moodle changed it to and re add the head script including the <head> tags

Anyway it worked for me hope it helps

Average of ratings: Useful (1)
In reply to Luis Rodero

Re: Inserting Javascript code in pages

by Jurgis Pralgauskis -
I tried to "insert" javascript functionality just loading page with it via <iframe> ;)
In reply to Jurgis Pralgauskis

Re: Inserting Javascript code in pages

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Hi Jurgis,
Could you elaborate on your method, please?
When you say you "tried", do you mean you did not succeed?
Joseph
In reply to Jurgis Pralgauskis

Re: Inserting Javascript code in pages

by Jurgis Pralgauskis -
it seems, that usually iframe is filtered out, and not shown.. (at least in forum posts)
so You'd need to hack a little bit..


my try is captured here
http://tadas.hn.org/~jurgis/moxlai/edutech/DHTML/moodle_test.htm
I used the idea in Quiz
In reply to Jurgis Pralgauskis

Re: Inserting Javascript code in pages

by Timothy Takemoto -

Dear Jurgis Pralgauskis
How come we can see into your quiz? Normally one has to be logged in. I would like to be able to allow guest access to quizes.

Or is this a complete mockup page that is not part of any moodle. Hmm. looking at the URL it would seem so.
sorry
Timothy

In reply to Luis Rodero

Javascript array ids

by Anne Grant -

I have just taken over a Moodle site so I have a lot to learn. The menu bar has drop-down lists that need to be linked to a content page. The first line of the drop-down list has a php?id=37. Please see image below. I tried adding ids of 38, 39 and 40 to the source file but that didn't work. Can you assist? 

Source code for array