简体   繁体   English

使用href accesskey聚焦父窗口

[英]focus a parent window using href accesskey

I included a bank calculator tool inside a website. 我在网站内包含了一个银行计算器工具。 This calculator is opened on a new window. 该计算器在新窗口中打开。 The problem I'm facing is that users need a shortcut to open multiple times the calculator, so I found the accesskey, it works the first time you use it, but if you go back to the main window (where accesskey shortcut is) and try to reuse the accesskey it will not work. 我面临的问题是用户需要多次打开计算器的快捷方式,因此我找到了accesskey,它在您第一次使用时就可以使用,但是如果您返回主窗口(accesskey快捷方式所在的位置),尝试重用accesskey,它将无法正常工作。 Any idea on how to solve it? 关于如何解决的任何想法?

<a accesskey="C" href="javascript:openCalculator();" title="Calculator">Calculator</a>

<script>
function openCalculator()
{
    window.open("calculator.asp","Calculator1",'resizable=yes, scrollbars=yes,Titlebar=Calculator,toolbar=false,status=yes,menubar=false,width=450,height=450');
}
</script>

You could use: 您可以使用:

document.onkeyup = function(e){
   e= window.event || e;
   if(67==e.keyCode) openCalculator();
}

I think it should work better than Accesskey. 我认为它应该比Accesskey更好。

EDIT: Just thought of this, you need to change: 编辑:只是想到这一点,您需要更改:

     window.open("calculator.asp","Calculator1",'resizable=yes, scrollbars=yes,Titlebar=Calculator,toolbar=false,status=yes,menubar=false,width=450,height=450');

To

     window.open("calculator.asp","_blank",'resizable=yes, scrollbars=yes,Titlebar=Calculator,toolbar=false,status=yes,menubar=false,width=450,height=450');

If the second param is named (set to something other than _blank), it won't open in a new window everytime, it will open in the one named Calculator1, so once it has one with the name, it won't open new windows anymore. 如果第二个参数被命名(设置为_blank以外的其他名称),它将不会每次都在新窗口中打开,它将在一个名为Calculator1的窗口中打开,因此一旦它具有一个名称,就不会打开新的窗户了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM