简体   繁体   中英

Cordova iframe working in iOS Safari but not in Android

I am working on a Cordova app, but have encountered a problem. The problem I am facing occurs in a script where a hidden form is being submitted to an iframe to preview a file. The script is as follows:

document.body.innerHTML = '\
<div class="topbar">\
    <div class="title">File</div>\
</div>\
<div id="content" class="content">\
    <iframe id="file-iframe" name="file-iframe" class="file-iframe" charset="UTF-8"></iframe>\
</div>';

var form = document.createElement("form");
form.setAttribute("method", "post");
form.setAttribute("action", "url_of_file");

form.setAttribute("target", "file-iframe");

var filenameField = document.createElement("input"); 
filenameField.setAttribute("type", "hidden");
filenameField.setAttribute("name", "q");
filenameField.setAttribute("value", file.filename);
form.appendChild(filenameField);

document.body.appendChild(form);

form.submit();
form.parentNode.removeChild(form);

When called the script is basically creating a view with an empty iframe and then creating a form to submit to it. While this works perfectly in the iOS Simulator even without Cordova (this is plain JavaScript yet), it fails on real Android devices. When investigating the log the following line appears:

00:43:16 D CordovaLog : file:///android_asset/www/index.html: Line 1 : Uncaught SyntaxError: Unexpected token ILLEGAL

00:43:16 I chromium : [INFO:CONSOLE(1)] "Uncaught SyntaxError: Unexpected token ILLEGAL", source: file:///android_asset/www/index.html (1)

Similar questions suggest that there are illegal white spaces from JSBin or similar sites, but this doesn't seem to be the same reason here, as the code hasn't been copied and actually works on iOS.

Why is this happening and how can it be fixed?

Thanks in advance

Looks like some illegal characters actually got into the script, still don't know why. At least it works now.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM