Using javascript to open search in new tab
I have a browser-based search utility with many .php files and many forms. My users select their query parameters from list boxes and submit the form; a new php page comes up that displays their results.
I've been asked to give my users the option of opening their 'results' page in a new tab in their browser, but my solution isn't really reliable; sometimes it works but sometimes it doesn't. I'm hoping someone can steer me toward a better approach.
I'm using the onkeydown, onkeyup, and onmouseover events to fire javascript functions. In the Body tags of my HTML, I put this:
Code:
<body onkeydown="pageDifferent(event, 'formSites')"
onkeyup="pageSame('formSites')"
onmouseover="pageSame('formSites');">
And my javascript functions:
Code:
function pageDifferent(pressedKey, formName) {
if (pressedKey.keyCode == 18) {
document.forms[formName].target='_blank';
}
}
function pageSame(formName) {
document.forms[formName].target='_self';
}
This works fine about 70% percent of the time, but the rest of the time my users' search results open in the same window. If I remove the 'onmouseover' part, it works all the time - presumably my onmouseover is overriding my onkeydown if it senses a tiny movement. But I need the onmouseover part, or something equivalent, to reset to '_self', so that a new tab only opens while the key is pressed.
I've tried using anchor tags (CTRL key does what I want by default), but that gives me funky results. I've tried various combinations of onkeydown and onkeypress, but nothing I've come up with does what I want all the time.
Can anyone point me in a direction that will help? Thanks for any replies.