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. 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.

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top