Javascript in news items

Javascript in news items

by steph . -
Number of replies: 10

Is it possible to add Javasript in the news items on the homepage of my moodle website? I have tried deactivating the TinyMCE html editor, but it still erases all my javascript code when I save it. 

Average of ratings: -
In reply to steph .

Re: Javascript in news items

by Itamar Tzadok -

Turn the editor off from your profile. You would have to have the editor off anytime you need to add or edit a post with code. smile

In reply to Itamar Tzadok

Re: Javascript in news items

by steph . -

I've tried that also and the javascript still disappears. It works in the html editor in a course, but not on the homepage news items. 

In reply to steph .

Re: Javascript in news items

by Itamar Tzadok -

Try to include a js src file rather than inline code. Which effect are trying to achieve? smile

In reply to Itamar Tzadok

Re: Javascript in news items

by steph . -

I am trying to add a link that will go to a different page whether you are on a PC or a iPad or iPhone. 

I am new to web programming, how do I add a js scr file?

In reply to steph .

Re: Javascript in news items

by Itamar Tzadok -

If that's just a link to another page why do you need js? You can add a link via the editor's insert/edit link button and enter there the url of the target page. smile

In reply to Itamar Tzadok

Re: Javascript in news items

by steph . -

I need the js to detect if the user is using an apple device. If they are, the link will direct them to a different page. 

In reply to steph .

Re: Javascript in news items

by Itamar Tzadok -

To include a js file you add a script tag like the following:

<script type="text/javascript" src="url-to-the-designated-js-file"></script>

smile

In reply to Itamar Tzadok

Re: Javascript in news items

by steph . -

I've turned off the editor, but still everything that is in the script tag disappears when I save. I tried it on a page in a course and it works. I copy pasted the code to the news items on the homepage and it doesn't work there. mixed