Script tag not rendering in HTML page
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.
Read full answer below ↓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 (4)
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
Thanks for reporting this, @hrdkzala.
Thanks for sharing your report about Script tag not rendering in HTML page. To help the team investigate and prioritize this:
Please provide:
- A minimal reproducible example (CodeSandbox/JSFiddle)
- Your GrapesJS version number
- Browser and OS information
- Any error messages from the browser console
- Steps to reproduce the issue
What helps most:
- Minimal code example (not your full project)
- Screen recording or screenshot showing the issue
- Expected vs actual behavior clearly stated
- GrapesJS configuration you're using
With these details, the maintainers can identify and prioritize a fix much faster. The GrapesJS team is very responsive to well-documented issues.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #5090
Component script function runs twice after page save
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? 112.0.5615.137 (Official Build) (arm64) Re...
Issue #5457
Editor Freeze on loadProjectData 0.21.7
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome 117.0 Reproducible demo link localh...
Issue #5263
Deleting a component without deleting its corresponding style, will adding new components later cause style conflicts?
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? latest version of Chrome Reproducible demo...
Issue #3627
[QUESTION]: I'm trying to duplicate the page, but the styles are not geting applied due to the Ids, changes to -2,-3 at the end.
This is what my function looks like. I am trying duplicate the page, the HTML part is fine but as css is applied through ids, when a new pa...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.
Browse free plugins →Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.
Browse premium plugins →Related tutorials
In-depth guides on the same topic.
Tutorial
How to Build a Production GrapesJS Editor: The Complete Walkthrough of Brief, Preset, Plugins, and Services
A complete walkthrough of building a production GrapesJS editor: how to choose a preset, pick plugins, and scope setup services without burning a sprint.
Tutorial
Embed GrapesJS in Your SaaS: A Weekend Guide
Embed GrapesJS in your SaaS and ship a white-label page builder over a weekend. Honest tradeoffs, real code, and the plugins that close the UX gap.
Tutorial
Big Updates: TinyMCE 8 and Placeholder 2.0 for GrapesJS
In May we shipped major updates to two of our most popular GrapesJS plugins — TinyMCE Inline Text Editor and Placeholder.
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.