Issue #3730Opened August 27, 2021by hrdkzala0 reactions

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)

artfAugust 29, 20210 reactions

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.

mingxin-yangSeptember 3, 20210 reactions

script function don't work after drag the block @artf

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

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.