M
M
Messi2018-03-23 10:27:32
JavaScript
Messi, 2018-03-23 10:27:32

How to download arbitrary text in html format displayed on a page?

Text is passed to the page (created in the wysiwyg editor) in the $model->content variable.
With the help of download I want to download the given text to a file.

$this->registerJs(<<<JS
(function() {
    
    $('.btn-download').on('click', function(e) {
        e.preventDefault();
        download(new Blob(["$model->content"]), "fileName");
    });            
})();
JS
)
?>

With such a call, I get the error "Uncaught SyntaxError: Unexpected identifier", in the code inspector I see that there is a problem with quotes (because the text has quotes too)
If you call it like this:
download("$model->content", "$name") ;
That error:
Uncaught SyntaxError: missing ) after argument list
Please tell me how to transfer the text there correctly?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question