Issue #2012💬 AnsweredOpened May 13, 2019by webdeveloper04290 reactions

How to add script for all widgets(like protectedCss)

快速解答by artf

You can initialize custom js in the canvas in this way:

Read full answer below ↓

Question

I want to add some functions for all components accessible. when initialize editor, there is a option like protectedCss. Isn't there a way javascript like above?

Answers (3)

artfMay 19, 2019

You can initialize custom js in the canvas in this way:

const editor = grapesjs.init({
  ...
  canvas: {
    scripts: ['https://.../script.js']
  }
});

webdeveloper0429May 20, 2019

Thank you. Btw what I want to need is inline javascirpt. not external link... regards.

artfMay 27, 2019

In that case, I suggest you access the document of the iframe and to append manually the inline script (to get the document use editor.Canvas.getDocument())

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins →
Premium option

Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.

Browse premium plugins →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.