在子窗口中跨域域,获得焦点。 [英] cross domain site in child window, get focus.

查看:82
本文介绍了在子窗口中跨域域,获得焦点。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1.我有两个链接,当用户点击链接时,子窗口打开并加载跨域URL。

如果用户再次单击它,我想通知用户或将焦点设置到已打开的窗口。我怎样才能做到这一点。我尝试在window.open函数调用中为窗口设置一个名称,但每当我尝试访问它时,它返回'' ACCESS IS DENIED ''







我尝试使用数组来存储已经打开的Windows网址,如果用户请求相同的网址,则会显示一条警告消息。但是我想将焦点设置到已经打开的窗口,用户正在请求。



2.父窗口关闭时如何关闭所有子窗口?



3.当用户关闭主窗口/浏览器时,如何触发注销按钮?



for the第一个问题我试过......



 newWindowsArray =  new 数组( ); 
var scrwid = $(window).width(); var scrht = $(window).height(); var winhgt = scrht - 140 ; var winwdth = scrwid - 20 ;
函数OpenWindow(目标,名称){
如果(checkItem(newWindowsArray,Target)){
openedWindow = window.open(目标,' _ blank'' < span class =code-string> width =' + winwdth + ' ,height =' + winhgt + ' ,status = 0,toolbar = 0,menubar = 0,location = 0,scrollbars = 1 ,可调整大小= 1,screenX = 0,screenY = 170,顶部= 170,左= 10' );
newWindowsArray [newWindowsArray.length] =目标;
var intervalId = setInterval(function(){
if (openedWindow.closed ){
clearInterval(intervalId);
if (newWindowsArray.length > 0 ){
for (i = 0 ; i < newWindowsArray.length; i ++){
removeItem(newWindowsArray,Target);
break ;
}
}
}
}, 10 );

}
}
函数removeItem(array,item){
if (array.length < span class =code-keyword>>
0 ){
for var i in array){
if (array [i] == item){
array.splice(i, 1 );
break ;
}
}
}
}
function checkItem(array,item){
if (array.length > 0 ){
for var i in array){
if (array [i] == item){
alert(' 窗口已经打开!); // 我想将焦点设置到打开的窗口。
return false ;
}
}
返回 true ;
}
其他 {
return ;
}
}






第3个问题




window.onbeforeunload:function(){触发按钮点击} //不工作.....



与...相同卸货功能。





任何建议表示赞赏..................

解决方案

(window).width(); var scrht =


(window).height(); var winhgt = scrht - 140 ; var winwdth = scrwid - 20 ;
函数OpenWindow(目标,名称){
如果(checkItem(newWindowsArray,Target)){
openedWindow = window.open(目标,' _ blank'' < span class =code-string> width =' + winwdth + ' ,height =' + winhgt + ' ,status = 0,toolbar = 0,menubar = 0,location = 0,scrollbars = 1 ,可调整大小= 1,screenX = 0,screenY = 170,顶部= 170,左= 10' );
newWindowsArray [newWindowsArray.length] =目标;
var intervalId = setInterval(function(){
if (openedWindow.closed ){
clearInterval(intervalId);
if (newWindowsArray.length > 0 ){
for (i = 0 ; i < newWindowsArray.length; i ++){
removeItem(newWindowsArray,Target);
break ;
}
}
}
}, 10 );

}
}
函数removeItem(array,item){
if (array.length < span class =code-keyword>>
0 ){
for var i in array){
if (array [i] == item){
array.splice(i, 1 );
break ;
}
}
}
}
function checkItem(array,item){
if (array.length > 0 ){
for var i in array){
if (array [i] == item){
alert(' 窗口已经打开!); // 我想将焦点设置到打开的窗口。
return false ;
}
}
返回 true ;
}
其他 {
return ;
}
}






第3个问题




window.onbeforeunload:function(){触发按钮点击} //不工作.....



与...相同卸货功能。





任何建议表示赞赏..................


1.I have two links, when ever user clicks on a link ,child window opens and loads the cross domain url.
If the user click it again,I want to notify user or set focus to the already opened window. How can I achieve this. I tried setting a name to the window in window.open function call, But whenever I try to access it, it return ''ACCESS IS DENIED''



I tried using an array to store already opened windows urls and if the user requests the same url, an alert message is shown. But I want to set focus to the already opened window, the user is requesting.

2.How to close all the child windows when parent window is closed?

3.How can I trigger logout button click when user closes the main window/browser?

for the first question I tried...

newWindowsArray = new Array();
       var scrwid = $(window).width(); var scrht = $(window).height(); var winhgt = scrht - 140; var winwdth = scrwid - 20;
       function OpenWindow(Target, Name) {
           if (checkItem(newWindowsArray, Target)) {
               openedWindow = window.open(Target,'_blank', 'width=' + winwdth + ',height=' + winhgt + ',status=0,toolbar=0,menubar=0,location=0,scrollbars=1,resizable=1,screenX=0,screenY=170,top=170,left=10');
               newWindowsArray[newWindowsArray.length] = Target;
               var intervalId = setInterval(function () {
                   if (openedWindow.closed) {
                       clearInterval(intervalId);
                       if (newWindowsArray.length > 0) {
                           for (i = 0; i < newWindowsArray.length; i++) {
                               removeItem(newWindowsArray, Target);
                               break;
                           }
                       }
                   }
               }, 10);

           }
       }
       function removeItem(array, item) {
           if (array.length > 0) {
               for (var i in array) {
                   if (array[i] == item) {
                       array.splice(i, 1);
                       break;
                   }
               }
           }
       }
       function checkItem(array, item) {
           if (array.length > 0) {
               for (var i in array) {
                   if (array[i] == item) {
                       alert('window already opened!');//I want to set focus to the opened window.
                       return false;
                   }
               }
               return true;
           }
           else {
               return true;
           }
       }




for 3rd question:

window.onbeforeunload:function(){triggered button click}//not working.....

same with unload function.


any suggestion is appreciated..................

解决方案

(window).width(); var scrht =


(window).height(); var winhgt = scrht - 140; var winwdth = scrwid - 20; function OpenWindow(Target, Name) { if (checkItem(newWindowsArray, Target)) { openedWindow = window.open(Target,'_blank', 'width=' + winwdth + ',height=' + winhgt + ',status=0,toolbar=0,menubar=0,location=0,scrollbars=1,resizable=1,screenX=0,screenY=170,top=170,left=10'); newWindowsArray[newWindowsArray.length] = Target; var intervalId = setInterval(function () { if (openedWindow.closed) { clearInterval(intervalId); if (newWindowsArray.length > 0) { for (i = 0; i < newWindowsArray.length; i++) { removeItem(newWindowsArray, Target); break; } } } }, 10); } } function removeItem(array, item) { if (array.length > 0) { for (var i in array) { if (array[i] == item) { array.splice(i, 1); break; } } } } function checkItem(array, item) { if (array.length > 0) { for (var i in array) { if (array[i] == item) { alert('window already opened!');//I want to set focus to the opened window. return false; } } return true; } else { return true; } }




for 3rd question:

window.onbeforeunload:function(){triggered button click}//not working.....

same with unload function.


any suggestion is appreciated..................


这篇关于在子窗口中跨域域,获得焦点。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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