grapesjs icon indicating copy to clipboard operation
grapesjs copied to clipboard

GrapeJS can't load javascript

Open phucphanJaneto opened this issue 8 years ago • 9 comments

Hi. I have some script tag in my html code (includes js file and internal javascript tag) But GrapeJS doesn't load any script and apply this.

Can I have any way load javascript to grapejs and export html include javascript code?

phucphanJaneto avatar Mar 09 '18 04:03 phucphanJaneto

Hi

You can allow script when you init grapesJS instance.

const editor = grapesjs.init({ ... allowScripts: 1, });

Hope that helps you.

vishal5033 avatar Mar 09 '18 05:03 vishal5033

@vishal5033 : many thanks for your helps. it works for me. The script file and internal js will show when export html. But I see the error message: image and image

can you help me?

phucphanJaneto avatar Mar 09 '18 07:03 phucphanJaneto

@phucphanJaneto try to post your code? maybe something is missing or you got the wrong syntax.

josefph avatar Mar 09 '18 11:03 josefph

Yes.

var newComps = editor.DomComponents;
window.newCom = newComps;
$.get(response.HtmlLink, function (e) {
      newComps.setComponents(e);
   })
})
window.editor.setComponents(newComps);

You can test with attach html. b0c0c79f-41e5-437d-aa12-4aa3bfb198df.zip

phucphanJaneto avatar Mar 09 '18 11:03 phucphanJaneto

@phucphanJaneto you're doing something wrong here

$.get(response.HtmlLink, function (e) {
	  // check the `e`, shoud be an HTML string or Component Object
      newComps.setComponents(e);
   })
})

artf avatar Mar 10 '18 13:03 artf

Yes. this is a HTML string. i load html file which sent to you.

phucphanJaneto avatar Mar 11 '18 00:03 phucphanJaneto

Hey, @artf

Can you see my comment above?

phucphanJaneto avatar Mar 12 '18 08:03 phucphanJaneto

Check better the response (it might be a case to escape the string) and if headers are correct

artf avatar Mar 14 '18 23:03 artf

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

lock[bot] avatar Sep 17 '19 21:09 lock[bot]