使用Cordova并使用inAppBrowser说在iphone上打开一个窗口。如何将表单同时发布到该新窗口实例中。我似乎可以使用GET请求打开外部或本地HTML文件,但我无法将数据发布到该新页面。我想做以下事情。但这会产生意外行为,看起来它会一遍又一遍地打开多个窗口。另外,如果我以任何方式更改代码,它都不会发布表单。
var ref = $window.open('modules/life/views/cordovaAutoParamed.html', target, options);
if (ref !== undefined && ref !== null) {
ref.addEventListener('exit', function(event) {});
ref.addEventListener('loaderror', function(event) {});
ref.addEventListener('loadstart', function(event) {
});
ref.addEventListener('loadstop', function(event) {
ref.show();
var fullAutoPostParamed = ' window.document.open(\'text/html\', \'replace\'); \
window.document.write(\'<html><body onload="document.forms[0].submit()"> \'); \
window.document.write(\' <form action="'+paramed.callbackUrl+'" method="post"> \'); \
window.document.write(\' <input type="hidden" name="Assertion" value="123" /> \'); \
window.document.write(\' <input type="submit" value="execute" /> \'); \
window.document.write(\' </form></body></html> \'); \
window.document.close();';
paramedLogger.error(fullAutoPostParamed);*/
ref.executeScript({code: fullAutoPostParamed });
ref.show();
});
此外,executeScript似乎无法在桌面上的Chrome等常规浏览器上运行。
答案 0 :(得分:0)
我认为您应该只调用window.document.write
个函数而不调用window.document.open
(当前文档是包含该表单的文档)。
然后,删除body onload
函数并在表单中添加ID:
<form id="myform">
最后,在ref.executeScript
添加另一个电话后
ref.executeScript({code: 'document.myform.submit();'})
发布表格。
关于无限循环:
我不知道为什么你这么多次打show()
,文档说方法:
显示隐藏打开的InAppBrowser窗口。如果InAppBrowser已经可见,则调用此方法无效。
关于executeScript方法: Docs says它也适用于浏览器。请检查您的控制台日志以获取相关信息。还尝试使用浏览器的调试工具检查代码的执行流程。