Add embedded code or JavaScript to a web page

Sometimes, you may want to go beyond the editing options on the ribbon and customize a web page by editing the underlying code. For example, you can:

  • Embed pre-generated IFRAME or OBJECT tags to add documents, videos, and other specific content.
  • Add JavaScript to create a custom form, do calculations, animate content, or control events, such as mouse clicks and page loading.

Security   We may remove some or all JavaScript code to prevent security problems, such as cross-site scripting, which can compromise your web site. If you are sure that your JavaScript code is safe and you want to ensure that JavaScript code is not removed, make sure you have design permission level or higher on the page.

Embed code on the page

  1. Browse to the web page where you want to add or edit the code.
  2. From the Page tab, choose Edit.
  3. Place your cursor where you want the inserted code to appear.
  4. From the Insert tab, click Embed Code.
  5. In the Embed window, add the embedded code or script that you want to add to the page.

The Embed window

  1. When finished, click Insert. Note the following:
  • If the code is safe, such as embedded code, it is entered inline on the page.
  • If you do not have design permission level or higher and the code is potentially unsafe, such as JavaScript, some or all of the code is removed.
  • If you do have design permission level or higher, and you enter potentially unsafe code, such as JavaScript, the code is completely entered in the Script Editor Web Part. In this case, make sure the code is safe.

 Note    You can also add the Script Editor Web Part directly on the page. The security check is the same.

  1. After you insert the code, verify that everything appears as you expect.
  • If the page looks correct, click Page > Save > Save, and then open the page in a new browser window to confirm.
  • If you experience problems you can’t resolve, then do not save the page. Instead, click Page > Save > Stop Editing > Cancel.

Learn more

There are other approaches you can take to customize code behind the pages on your web site:

For a summary of all related topics, see Public Website help for Office 365.

 
 
Applies to:
SharePoint Online Small Business, SharePoint Online Website