Topic: Save file in wysiwyg editor
Luca Di Bello free asked 4 years ago
Expected behavior Hi, I have a problem with wysiwyg editor on bootstrap. Because I need to save a file in the editor, I inserted a save button in the editor and included the FileSaver.js library in the index page.
Actual behavior When I press the save button to save the contents of the textbox the following error is displayed: Uncaught ReferenceError: saveDynamicDataToFile is not defined at HTMLButtonElement.onclick (index.html:62)
Resources (screenshots, code snippets etc.)
/*new button save in toolbar in wysiwyg.js*/
<li><button onclick="saveDynamicDataToFile();" data-action="save" data-tooltip data-placement="bottom" title="${this.options.translations.save}"><i class="fas fa-save"></i></button></li>
/*my function to save a file in wysiwyg.js*/
function saveDynamicDataToFile() {
var userInput = document.getElementById("hypertext").value;
var blob = new Blob([userInput], { type: "text/plain;charset=utf-8" });
saveAs(blob, "dynamic.txt");
}
/*inclusions in index.html*/
<script type="text/javascript" src="js/jquery-3.4.1.min.js"></script>
<script type="text/javascript" src="js/FileSaver.min.js"></script>
<!-- Bootstrap tooltips -->
<script type="text/javascript" src="js/popper.min.js"></script>
<!-- Bootstrap core JavaScript -->
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<!-- MDB core JavaScript -->
<script type="text/javascript" src="js/mdb.min.js"></script>
<script type="text/javascript" src="js/wysiwyg.js"></script>
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Opened
- ForumUser: Free
- Premium support: No
- Technology: MDB jQuery
- MDB Version: 4.19.1
- Device: Pc Windows
- Browser: Chrome
- OS: Windows 10
- Provided sample code: No
- Provided link: No
Krzysztof Wilk staff commented 4 years ago
Hi!
Did you put your function between tags? If yes - I think you can use event listener instead of onclick attribute, but could you use our online editor that you can find here: https://mdbootstrap.com/snippets/ (you have to swap your FileSaver.min.js with a link from CDN, here you have an example https://github.com/eligrey/FileSaver.js/wiki/FileSaver.js-Example) and prepare working example of your problem? That will help to recognize the problem :)
Best regards