基本思想是通过单击书签来登录页面
我正在尝试创建一个 chrome 书签,它应该
- 加载页面
- 填写详细信息(通过调用
fillDetails()
函数实现) - 提交表格
代码
javascript:(function(){
window.location ="http://www.example/login.html";
window.onload = fillDetails();
function fillDetails() {
if(document.URL.indexOf("http://www.example/login.html") > -1){
document.getElementById("username").value="uname";
document.getElementById("password").value="pass";
document.getElementById("login").submit();
console.log("Success");
} else {
console.error("Cannot Insert values");
}
}})();
错误
fillDetails()
在页面加载之前执行,但它应该在页面加载之后执行
最佳答案
您将 window.onload
设置为 fillDetails()
的执行结果,而不是将其设置为函数本身。应该是:
window.onload = fillDetails;
关于页面加载后 JavaScript 函数调用不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32635573/