window.open之后的代码不会被执行 [英] Code after window.open doesn't get executed
问题描述
我最近开始学习javascript,我正在尝试制作一个小脚本,通过填写用户名/密码字段,然后点击提交按钮来自动化登录过程。
I recently started learning javascript, and I'm currently trying to make a small script to automate a login procedure by filling the user name/password fields, and then clicking the 'Submit'-button.
我的代码如下:
window.open("");
document.getElementById('ctl00_Username').value = "XXXX";
document.getElementById('ctl00_Password').value="XXXX";
document.getElementById('ctl00_ButtonLogin').click();
如果我运行一次,则会打开网站,但不会填写任何文本字段。
如果我运行代码两次(当网站已经打开时)登录成功。
If I run it once, the site is opened but no text fields are filled.
If I run the code twice (when the site is already opened) the login is successful.
我尝试在window.open之后添加console.log,但由于某种原因,似乎永远不会被调用。
I tried putting "console.log" after "window.open", but for some reason that never seems to get called.
我可能做错了什么?
编辑:删除不必要的代码。我也不再确定文档对象实际指向新打开的窗口。对console.log和alert的调用似乎也没有做任何事情。
Removed unnecessary code. I am also no longer sure that the document-object actually points to the newly opened window. Calls to "console.log" and "alert" don't seem to do anything, either.
是否可以从窗口获取正确的文档对象?
是否可以使用window.open然后访问新的文档对象?
帮助将非常赞赏!
Is it possible to get the correct document-object from the window? Is it even possible to use "window.open" and then access the new document-object? Help would be greatly appreciated!
推荐答案
1.将您的值作为查询字符串传递。示例:www.test.com?username = bro& password = hub。
2.在另一页上粘贴以下代码。
1.Pass your values as query string. Example: www.test.com?username=bro&password=bro. 2.On the other page paste the below code.
$(function () {
$(document).ready(function () {
var amount = $('money').val();
var from = "INR";
var to = "SGD";
$.ajax({ type: "POST",
url: "WebService.asmx/CurrencyConversion",
data: "{amount:" + amount + ",fromCurrency:'" + from + "',toCurrency:'" + to + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
var money = $(".money").val();
$(".money").replace(money, data.d);
}
});
});
});
3.现在也粘贴此代码。
3.Now paste this code too.
var uname = getUrlVars()["username"];
var psw = getUrlVars()["password"];
4.您将在上述变量中获得价值。尽情享受您想做的任何事情。
4.You will be having values in the above variables.Enjoy doing whatever you want.
这篇关于window.open之后的代码不会被执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!