Script tag not rendering in HTML page
Question
I created the component as below.
const script = function() {
const script = document.createElement('script');
script.src = 'http://localhost:8888/builder/sites/site1/assets/js/jquery-1.12.4.min.js';
document.body.appendChild(script);
});
editor.Components.addType('comp-with-js', {
model: {
defaults: {
script
}
}
});
editor.BlockManager.add('site_1', {
label: 'Template 1',
category: 'Template',
content: '<div> HERE is my content </div>'
});
site_1 - is my readymade template and it has CSS and javascript.
CSS loads properly with the "content" but javascript doesn't so I created component for javascript.
On the HTML page, It shows the jquery file is added but doesn't work. I checked in view source.
If I made any external javascript file which simply alert("test"), but it doesn't work on html page.
I am using NuxtJS + Grapesjs.
Please advise me about this issue.
Answers (3)
Sorry but I don't understand where is your issue. You have created comp-with-js component but then you don't show where you are using it...
Please, provide a reproducible demo.
script function don't work after drag the block @artf
Related Questions and Answers
Continue research with similar issue discussions.
Issue #3342
jQuery not working for script in component
Hi! I have tried adding jquery in canvas as well as in index.html I am adding it in canvas like this- canvas = editor.Canvas; const script1...
Issue #2763
GrapesJs and PHP - store and load data to show in editor and as HTML page as well
I am using GrapesJS to build a simple webpage. I included the script in the following way inside head part : I am using GrapesJS to build a...
Issue #721
adding component script js
I have question about injecting script js into GrapesJs. Can I adding <script> into grapesJS using function editor.getComponents().add() an...
Issue #2705
[Question] Adding image sizes to image
When I add an image attribute to the page I noticed that inside of the component the image has attributes to it. When I call my images into...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.