[英]How do I use jQuery/JavaScript to open a Popup Window/Tab (ASPX Login Page) & then pass values to opened window/tab on DOM Ready Event of it?
We currently have two asp.net 2.x web applications and we need to perform the following functionality: 当前,我们有两个asp.net 2.x Web应用程序,我们需要执行以下功能:
From one application, we want to auto-login to the other web application automatically in a new tab; 我们希望从一个应用程序在新选项卡中自动登录到另一个Web应用程序; using the same browser instance/window. 使用相同的浏览器实例/窗口。
So the process is: 因此,过程为:
Open New Window/Tab With Second System URL/Login Page Wait For Popup Window/Tab Page To Load (DOM Ready?) 使用第二个系统URL /登录页面打开新窗口/标签页等待弹出窗口/标签页加载(DOM准备好了吗?)
OnPopupDomReady { Get Usename, Password, PIN Controls (jQuery Selectors) and Populate In Code Then Click Login Button (All Programmatically). OnPopupDomReady {获取用户名,密码,PIN控件(jQuery选择器)并在代码中填充,然后单击“登录”按钮(全部以编程方式)。 } }
I am currently using JavaScript to Open the window as follows: 我目前正在使用JavaScript打开窗口,如下所示:
<script type="text/javascript">
$(document).ready(function () {
$('a[rel="external"]').click(function ()
{
window.open($(this).attr('href'));
return false;
});
});
</script>
I would like to use jQuery chaining functionality if possible to extent the method above so that I can attach a DOM Ready event to the popped up page and then use that event to call a method on the code behind of the popped up page to automatically login. 如果可能,我想使用jQuery链接功能来扩展上述方法,以便可以将DOM Ready事件附加到弹出页面,然后使用该事件在弹出页面后面的代码上调用方法以自动登录。 Something similar to this (Note: The following code sample does not work, it is here to try and help illustrate what we are trying to achieve)... 与此类似(注意:以下代码示例不起作用,在这里尝试并帮助说明我们正在尝试实现的目标)...
<script type="text/javascript">
$(document).ready(function () {
$('a[rel="external"]').click(function () {
window.open($(this).attr('href').ready(function ()
{
// Use JavaScript (Pref. jQuery Partial Control Name Selectors) To Populate Username/Password TextBoxes & Click Login Button.
})
});
});
</script>
Our architecture is as follows: We have the source for both products (ASP.NET WebSite[s]) and they are run under different app. 我们的体系结构如下:我们都有两种产品的源代码(ASP.NET WebSite),它们在不同的应用程序下运行。 pools in IIS. IIS中的池。
When you open a window with window.open
, the new window gets a property called window.opener
which references the parent window. 当使用window.open
打开窗口时,新窗口将获得一个名为window.opener
的属性,该属性引用父窗口。 So code in your child window can call functions in the parent window, for instance: 因此,子窗口中的代码可以调用父窗口中的函数,例如:
In Window A: 在窗口A中:
// Declared at global scope => ends up as property on `window`
function phoneHome(str) {
alert(str);
}
In Window B (the child window): 在窗口B(子窗口)中:
$.ready(function() {
if (window.opener && window.opener.phoneHome) {
window.opener.phoneHome("Hi, Ma!");
}
});
(Using $.ready
in the child window requires that the child window have jQuery loaded.) (在子窗口中使用$.ready
要求子窗口已加载jQuery。)
In the above all I've done is have the child window trigger a function in the parent window with a message, but of course the function call can carry any data you want it to. 上面我所做的就是让子窗口在父窗口中触发一条带有消息的函数,但是函数调用当然可以携带您想要的任何数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.