0

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>
Gerardo Abdo
  • 1,150
  • 3
  • 10
  • 16
  • What do you mean? If you leave a certain window, the `accesskey` isn't available. So how do you expect it to work when the window is switched? – Ian May 09 '13 at 04:26
  • thank you for the clarification, I just made the correction. I mean when I go back to the main window where accesskey is located – Gerardo Abdo May 09 '13 at 04:31

1 Answers1

1

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.

dave
  • 62,300
  • 5
  • 72
  • 93
  • Thank you for sharing. Home page is where I need to open calculator as many times user needs. The problem is when Calculator opens and I go back to home page and need to reopen the calculator, is does not opens again – Gerardo Abdo May 09 '13 at 04:42
  • modified answer with alternate way of doing it, still using C as the key to press – dave May 09 '13 at 04:48
  • That works, thank you. Is there a way to focus the previously opened window, instead of open multiple child windows? – Gerardo Abdo May 09 '13 at 15:29
  • Look here: http://stackoverflow.com/questions/6032101/how-to-set-the-focus-to-a-child-window-without-refreshing-it – dave May 09 '13 at 17:00
  • I can reopen the window if I click the link, the problem is when I try to use acceskey – Gerardo Abdo May 09 '13 at 18:15