I have a javascript that is supposed to create a download link to a text file when a button is clicked but I am getting an "Invalid left-hand side expression" error with it.
The js looks like this:
(function () {
var textFile = null,
var makeTextFile = function (text) {
var data = new Blob([text], {type: 'text/plain'});
// If we are replacing a previously generated file we need to
// manually revoke the object URL to avoid memory leaks.
if (textFile !== null) {
window.URL.revokeObjectURL(textFile);
}
textFile = window.URL.createObjectURL(data);
return textFile;
};
var create = document.getElementById('create');
create.addEventListener('click', function () {
var link = document.getElementById('downloadlink');
link.href = makeTextFile({{request_string}});
link.style.display = 'block';
}, false);
})();
I've also tried doing this:
var text_string = {{request_string}}
link.href = makeTextFile(text_string);
Where {{request_string}}
looks like this:
----------------Request File Generated 2015-06-30 17:23:16.324439------------------
WINDOW_START | WINDOW_END | DURATION | SAT | TYPE | PRIORITY |
--------------------------------------------------------------------------------
2015/01/02 00:00:00 | 2015/01/22 00:00:00 | 500 | F7 | NOMINAL | 5 |
And the html looks like this:
<div class="panel panel-body">
<button id="create">Create file</button>
<a download="info.txt" id="downloadlink" style="display: none">Download</a>
</div>
The {{request_string}}
is type str so I'm not sure what the problem is. Can anyone tell me what I'm doing wrong?
Thanks!!
我最终使用document.getElementsByTagName('pre')
而不是尝试传递包含字符串的变量。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.