我正在学习JavaScript,因此决定创建一个脚本来
但是在页面从第1行打开之后,脚本的其余部分没有运行。
我如何完成此任务?
loginPage=open("abc.com"); //Open this page to fill a form there
var mainPage;
loginPage.onload=function(){ //once the page gets loaded fire this function
document.getElementById("username").value="123456789"; //fill username with this value
document.getElementById("password").value="abcdefghijk"; //fill password with this value
mainPage=document.getElementsByClassName("loginbutton")[0].click(); //press the login button
}
mainPage.onload=function(){
x=document.getElementsByClassName("tabletext"); //grab the table
target=x[22]; //since the content is in the 22nd index, assign it to target
console.log(target.textContent); //log the value of text inside target to console.
}
答案 0 :(得分:0)
Is "abc.com" the same domain as the site that you're executing this script on? If it's not, it's simply not possible due to the fact that you're violating CORS / browser security measures. You cannot read the content from another domain using JS that doesn't explicitly allow all origins.