I'm using the code below to open a button link using both the left and the middle mouse buttons. As it is now, if you press the middle button, a new tab opens, and then you have to manually click that tab to see its content. I'd like to point out this only happens in FireFox. In Chrome however, the new tab is opened and then also brought into focus right after you middle-click the button. Is there a quick way to make the script work the same way in FireFox as it does in Chrome? Thank you, Alex CODE SOURCE: https://stackoverflow.com/questions/40946442/how-can-i-make-a-javascript-link-openable-via-middle-click <html> <head> <script language="javascript" type="text/javascript"> function open_on_middle_click(event,url,target) { var x = event.buttons; if (x == 4) { window.open(url, target); } } </script> </head> <body> <div onclick="window.open('https://www.google.com')" onmousedown="open_on_middle_click(event,'https://www.google.com','_blank')" style="width: 120px; height: 20px; font-family: arial; border: 1px solid black; text-align: center; cursor: pointer;">button</div> </body> </html> Code (markup):
I thought that window.focus() after window.open() could work but it doesn't. If you control opened URL too, you can try to implement a Window Rollover technique, but there will be some flickering because it closes and reloads the first page.
Is there any way you could implement some sort of alt+tab command so the window will not be in focus then the script of alt+tab will bring it to the forefront. Note this is above my paygrade but every idea counts and I believe its a solid one.
Generally with many adblockers killing off scripted window.open, this is bad... but then opening new windows whether the user wants it or not is also bad since it prevents conventional navigation. If someone WANTS a new window let them middle-click or ctrl-click, don't try to shove it down the user's gullet. That's why target="" was deprecated in 4 Strict and why it's unbelievably DUMBASS that it's back in 5. Also, this isn't 1997, we don't say lang="JavaScript" anymore. This also isn't 2011, we don't say type="text/JavaScript" anymore either. Likewise one should NOT be using a DIV as a click hook, you should NOT be attaching events with onevent attributes in the markup, you should NOT be slopping static style="" crap into the markup like that, etc, etc, etc... Just make it a normal blasted <a>nchor and be done with it.