Add embedded code or JavaScript to a web page

Note: The SharePoint Online Public Website information in this article applies only if your organization purchased Office 365 prior to March 9, 2015. Customers who currently use this feature will continue to have access to the feature for a minimum of two years after the changeover date of March 9, 2015. New customers who subscribed to Office 365 after the changeover date don't have access to this feature. Moving forward, Office 365 customers have access to industry-leading third-party offerings that enable them to have a public website that provides a complete online solution and presence. For more information about this change, see Information about changes to the SharePoint Online Public Website feature in Office 365.

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 Note:  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

  6. 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.

  7. 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.

Connect with an expert
Contact us
Expand your skills
Explore training

Was this information helpful?

Thank you for your feedback!

Thank you for your feedback! It sounds like it might be helpful to connect you to one of our Office support agents.