window.open之后的代码不会被执行 [英] Code after window.open doesn't get executed

查看:1150
本文介绍了window.open之后的代码不会被执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始学习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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆