How to remove script tag which is added by add block manager script
Question
Hello @artf
I want to export final/production based html content excluding the script(Only which is added by block manager). Suppose i am adding a new block using block-manager, like
bm.add("image-cropper",
{
label: '<div class="gjs-block-label">Image Cropper</div>',
tab: "2",
content: {
script: function () {
// This is for an example actually i want to do something difference which only used for the editor mode not in live/exported code.
document.getElementById(''staticId').style.display = "none";
},
content: '<div><h1>Hello</h1><img id="staticId" /><div>'
}
}
)
Now when i put this block into the editor then it will create a div tag into the document and also creates the script like,
<script>
setTimeout(function() {
var item = document.getElementById('i5ziqj');
if (!item) return;
(function(){
// Scripted code is here
}.bind(item))()
}, 1);
</script>
So, while i am trying to fetch whole page html code using editor.getHtml() i also get above mentioned script. Actually i don't want this generated script(generated by block-manger only script).
Can we prevent this block-manager generated script while we fetched?
Answers (3)
jsInHtml……false
editor.Canvas.getWrapperEl().innerHTML
@AkibDeraiya123 use jsInHtml option https://github.com/artf/grapesjs/blob/6cb73f328fcc1b3771a483160d6d6f5f8d34b80c/src/editor/config/config.js#L108
@thinkanymore no, you should never use the raw HTML inside the canvas' wrapper
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1817
Change HTML content while block is render in editor
Hello @artf I have one block into block manager like As per above script inside the block, i want to add dynamic HTML content while this bl...
Issue #511
Cannot edit the content after update it via block manager API
Hello @artf sorry for my last issue, I must create a new issue, my problem is got error like this EDIT : sorry i just fixed my last issue w...
Issue #555
Add external script in script while creating new component
Hello @artf How can I pass external script link while creating a component? like this way, bm.add('test-block2', { label: 'Test block2', at...
Issue #634
How can I pass content with script?
I made custom component like this way and used script as well then script is working fine but I am not able to select component. Is there a...
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.