2

So I have a small bit of HTML and Javascript that I want to embed in a basic page. I go to edit the page, turn off rich text editing, and paste the HTML/javascript. I save, and then the javascript portion gets deleted while the HTML stays.

Is there any reason for this?

It is worth noting that the site is maintained and run by the university, although I have full permissions.

Other people say just add a bit of php and add_jscript(), but don't say where that goes, or how to get to that file.

EDIT: So I contacted the IT department and they suggesting adding the script as a block, and then adding the block to the page. Thanks for all your help!

5
  • Javascript gets filtered out when you use it in body or any kind of textarea. Add javascript using drupal_add_js in theme's template file. – Sumit Madan Nov 5 '14 at 16:42
  • Is there a way to get at that file from the website itself? I'm limited by the fact that the files are on a server I don't have access to.... – Guest Nov 5 '14 at 17:16
  • I dont understand?? You have your javascript code right?? – Sumit Madan Nov 5 '14 at 17:20
  • I've developed it on the side. I'm now trying to put it into a drupal page, and when I insert it in the HTML it deletes itself. The webpage is managed by the university so I'm starting to think it's there settings that are in the way. – Guest Nov 5 '14 at 17:30
  • I mean to say that write hook_preprocess_page in your template.php file and add it using drupal_add_js() by adding current_path() condition if you want to add it on specific pages. – Sumit Madan Nov 5 '14 at 17:38
9

It looks like what's happening is your text format settings are stripping the JS out of the page. You can edit the formats by going to /admin/config/content/formats, or you may just need to select a different format for the node in question (under the body field when you edit the node).

If you need the JS available on several pages, have a look at: https://www.drupal.org/node/304255.

5
  • I think my problem is with settings that the university is imposing. I don't have permission for /admin/config/content/formats, and the text format is in full HTML – Guest Nov 5 '14 at 17:16
  • So you don't have full permissions? I think by default the Full HTML format strips out all JavaScript. Are there any other formats to choose from? Do you have permissions to create blocks? Do you have filesystem-level access to the server? – universalhandle Nov 5 '14 at 17:31
  • I have as many permission as I can be granted, however I think the IT department has restricted some. I don't have file system access – Guest Nov 5 '14 at 17:40
  • Generally, site administrators allow only very trusted users to post JavaScript because it does pose a security concern. If the IT Department has disallowed users from adding JavaScript content, there's nothing you can do. Are there other text formats besides "Full HTML" to choose from? – universalhandle Nov 5 '14 at 17:55
  • filtered and plain text. – Guest Nov 6 '14 at 21:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.