javascript - 根据在 WebView 中查看的当前页面注入不同的 JavaScript
问题描述
请告诉我根据当前在 WebView 中查看的页面,将特定 JavaScript 注入 WebView 的正确方法?
我想展示 2 个步骤。第 1 步成功,但是当 WebView 加载第二个页面时,JavaScript 的第二步不成功。
const injectedJavaScript: = `
let currentStep = "step1";
if(currentStep === 'step1') {
document.getElementById('username').value = '${
this.props.username
}'; document.getElementById('password').value = '${
this.props.password
}'; document.getElementById('login').click();
currentStep = 'step2';
} else if(currentStep === 'step2' && window.location.href === "https://www.example.com") {
currentStep = 'download';
document.getElementsByClassName('button')[0].click();
}
`;
<WebView
ignoreSslError={true}
source={{ uri: "https://www.example.com" }}
style={{ marginTop: 20, height: 400, width: 400 }}
injectedJavaScript={injectedJavaScript}
javaScriptEnabledAndroid={true}
onError={() => this.webviewError(e)}
startInLoadingState={true}
scalesPageToFit={true}
/>
解决方案
推荐阅读
- programming-languages - 上下文无关语法设计 - 为什么不允许这样做?
- sql - 获取保存在多行中的相应代码
- docker - Rancher中启动pod后如何注册gitlab runner
- html - css 悬停返回过渡
- mysql - 带有多个 SELECT 语句的 SQL IF ELSE
- javascript - 我尝试使用 selenium java 一个一个地打开多个链接,但是在做时我得到了陈旧的元素引用异常
- amazon-web-services - AWS 应用程序负载均衡器:503 网关超时
- java - 我想为长值创建一个线程安全的
- c++ - 在 VS 代码中调试时无法打开“osteram.tcc”和“ios_base.h”
- python-3.x - 是否存在类似followin的东西?('''select * from TABLE where ? in FIELD''',(VAR))