javascript - 如何使用 location.href 或其他命令在 Flutter Webview 内的 Javascript 中加载页面 *syncronous*
问题描述
我想加载一个页面:
window.location.href='http://www.g1.com.br';
或通过使用
window.location.assign('http://www.g1.com.br');
然后对这个页面执行下一个命令。
如果我在浏览器的控制台中执行下面的代码,它将在页面加载之前发出警报:
window.location.href='http://www.g1.com.br';
alert('oi');
例如,在 dart lang 中,如果 href 是一个加载页面的异步函数,我会这样做:
href.load('http://www.g1.com').then(execJs(myJsVar));
我想要实现的是在 Flutter 中运行的 WebView 中使用 javascript 进行一些网络抓取。我发现在几个页面之间导航而不处理onPageFinished
颤振的 WebView 方法的方式是完全在 WebView 内的 Javascript 中进行导航。
但是我对Javascript不太了解。href
并且assign
似乎是异步功能,但如果可能的话,我不知道如何对其应用某种方式then
。
真正的代码:
我加载一个页面并在该页面上执行其他命令来填写表格。比我加载第二页并做同样的事情,
window.location.assign('%targetUrl%');
document.querySelectorAll('#email')
.forEach(
function (field, index, arr) {
field.value = '%username%';
field.dispatchEvent(new Event('input'));
}
);
document.querySelectorAll('#pass')
.forEach(
function (field, index, arr) {
field.value = '%password%';
field.dispatchEvent(new Event('input'));
}
);
window.location.assign('%targetUrl2%');
/// fill other forms, submit....
解决方案
推荐阅读
- multiprocessing - 在多处理器系统中禁用中断的过程是什么?
- c - 如何在纯 c 中创建图形画布以显示图形图形,而无需任何库和平台独立
- oracle - SL 无代
- reactjs - 无法配置现有的 React-Native 项目
- javascript - 如何在firebase实时数据库中限制用户每15分钟发帖一次
- android - 鉴于我已添加依赖项,无法解析 firebasedatabase
- angular - 无法将类属性添加到 Angular 7 中的 DOM 元素
- sql-server - 将计数值分组
- reactjs - 用ant-design在react js中提交后清除表单输入字段值
- python - 在 Python 中从列表中检索浮点值