Triyugi Narayan Mani Triyugi Narayan Mani - 6 months ago 42
jQuery Question

Javascript and ctrl key conflict

There is

where I am using
function to redirect on some other page.

But when I am using ctrl key and mouse, the link is opening in next tab as well as in same tab. Ideally, it should open in new tab only.

Code is as follows:

<div onclick="window.location='some page url'">


Just do this :

<a href="some page url">

So, when you click it's open in the same tab and when you press ctrl key, it's opening in a new tab.

EDIT : So now try this :

<div onclick="doRedirect()"></div>

            cntrlIsPressed = true;

        cntrlIsPressed = false;

    var cntrlIsPressed = false;

    function doRedirect()
 'some url','_blank');
           window.location('some url');


You can also specify the url in parameters.