问题描述
我使用popup.focus()在单击按钮后聚焦一个弹出窗口。对于除**** EDGE ****浏览器之外的所有浏览器,focus()工作正常。我面临的问题是间歇性的。有时我能够在浏览器上查看弹出窗口(子弹出对话框),有时在浏览器后面,即在桌面上,我可以通过任务栏上的闪烁来识别弹出窗口是否打开。
I am using popup.focus() to focus a popup window after a button is clicked. The focus() is working fine for all the browsers except for ****EDGE**** browser. The issue I am facing is intermittent. At times I am able to view the popup window (child popup dialog box) on the browser and at times behind the browser i.e. on the desktop and i am able to identify that the popup is open by the flashing on the task bar.
任何建议都会非常感谢
Any suggestion would be really appreciated
var popup = new PopupWind(url,'config')
popup.setFeature('height', height)
popup.setFeature('resizable', 'no')
popup.setFeature('scrollbars', 'no')
popup.setFeature('left', xLoc) // IE
popup.setFeature('top', yLoc)
popup.setFeature('screenx', xLoc) // NS
popup.setFeature('screeny', yLoc)
popup.open()
popup.focus();
我尝试过使用它来使focus()在EDGE中工作,但它没有b
$ b
I tried using this to make focus() work in EDGE but it did not
popup.blur();
setTimeout( popup.focus,0);
推荐答案
我有一个解决方案/ Hack
请在您的Edge浏览器中打开解决方案的链接
该窗口没有间歇性聚焦!
问题在于您需要将页面的焦点弄乱。如果你打开一个弹出窗口,然后专注于父页面,那么只需移动一个像素的父页面即可。点击该按钮将重新弹出对话框。
The issue is that you need to mess with the focus of the page. if you open a popup and then focus on the parent page, then move the parent page even just 1 pixel. Clicking the button will focus on the popup again.
因此,对于窗口方法似乎不起作用的残缺Web浏览器,除了等待几个(bug)。
So for a crippled web browser where window methods don't seem to work what can you do other than wait for a few years for them to fix their focus() bug.
好的,破解是通过生成一个临时空的弹出窗口从父窗口移除焦点。然后关注主弹出窗口并关闭临时弹出窗口。所有包裹在一个setTimeout @ 300毫秒,任何更低,它似乎并没有为我工作。
Well, the hack is to remove the focus from the parent window by generating a temp empty popup window. Then focusing on the main popup and closing the temp popup. All wrapped by a setTimeout @ 300ms, any lower and it didn't seem to work for me.
HTML
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<div id="button" class="bttn">Open Popup</div>
<div id="focus" class="bttn focus">Focus on Popup</div>
JAVASCRIPT
JAVASCRIPT
// This is the main guts of this page!
var isMSEdge = function() {
return window.navigator.userAgent.toLowerCase().indexOf('edge') > -1;
};
$(function() {
var $bttn = $('#button');
var $focusBttn = $('#focus');
var tempWin;
var testWindow;
$bttn.on('click', function() {
testWindow = window.open('', "pocketninja", "width=300, height=300");
$focusBttn.show();
$(this).hide();
});
$focusBttn.on('click', function() {
if(testWindow && isMSEdge()) {
tempWin = window.open('', 'temp', 'width=1, height=1');
setTimeout(function() {
testWindow.focus();
tempWin.close();
}, 300);
}
else {
testWindow.focus();
}
});
});
这篇关于focus()在边缘浏览器中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!