1

I have some HTML within a content web part.

For some reason when I add in the following code to my divs it removes it when I click ok and try to save it.

onclick="location.href=http://www.google.com;"

It's on a web part page and it doesn't do it on wiki pages I have on the site.

1

The Content Editor webpart (CEWP) does not allow adding javascript directly in the webpart.

  • If this is 2013 you can try the Script Editor webpart as described here.

  • In 2010, or if you still want to add the CEWP in 2013, you can use the option to link in the content from a text file as described here

3
  • I have a CEWP in another page (its a wiki page) which allows me to insert this line with no issues which is odd.
    – Sean
    Aug 5 '14 at 14:11
  • 1
    It could depend on whether it is a publishing page, wiki page or webpart page. I recall there is some differences in if they strip javascript or not Aug 5 '14 at 14:15
  • The first link for Script Editor Webpart gives 403 Forbidden error
    – Tikhon
    Jun 1 '18 at 12:57

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.