Sign up | Lost password? | Help

[ advanced search ]

Middle clicking javascript links

Forums » Opera Community » General Opera topics » User JavaScript


Go to last post

Tuesday, 20. February 2007, 06:01:13

xErath

javascript guru

avatar

Posts: 6404

Norway

Opera Software

Middle clicking javascript links

This small script does something really useful.
It detects link which open new windows either by javascript, or using a blank target.
If these links are middle-clicked, then the window that pops up is opened in the background. Javascript links are treated seamlessly. Their code is executed normally, and if they open a new window, in the background it'll be.
A note. For this to fully work, you must have "Allow lowering of windows" ticked in the javascript preferences, else, the newly opened window will be in the foreground.

here you go :wink:
middleclick.js

Feedback and bug reports are wellcome.

Tuesday, 20. February 2007, 09:19:53

d.i.z.

bug hunter

avatar

Posts: 2942

Poland

Is it just me or Opera won't parse utf8 encoded scripts with BOM?
I need to manually remove bom or else I just see inline script compilation error.

Wednesday, 21. February 2007, 00:00:07

xErath

javascript guru

avatar

Posts: 6404

Norway

Opera Software

Originally posted by d.i.z.:

Is it just me or Opera won't parse utf8 encoded scripts with BOM?


urgh :irked: ! I knew this happened, but it doesn't happen in Linux.

Wednesday, 21. February 2007, 08:13:37

xErath

javascript guru

avatar

Posts: 6404

Norway

Opera Software

Originally posted by Stoen:

The only problem is that if alert/prompt/confirm is in the event listener then the listener will silently fail.

I found this too. Middle clicking fires events but alerts don't appear.

You execute the javascript code immediately. I avoided this, since the code might require event listeners previously being invoked.

But supporting buttons is a neat idea :wink:

Wednesday, 21. February 2007, 10:27:13

Stoen

avatar

Posts: 1109

Originally posted by xErath:

You execute the javascript code immediately. I avoided this, since the code might require event listeners previously being invoked.


All event listeners should be handled, the fake click event should take care of it. Are you talking about mousedown/up event listeners? In which case AfterEvent.mousedown can be used and a mouseup event can be fired to more closely emulate a normal click.

Friday, 23. February 2007, 07:07:54

Stoen

avatar

Posts: 1109

Added option to cache the evaluated javascript url, may speed things up but not really necessary since it is the window.open that causes the most delay, everything else is pretty much instant

Now also works when scripts modify window.location

Script should now work from almost every type of link, the only obvious exception I can come up with is a link that submits a form through javascript

middleclickJSOverride.js

Friday, 25. May 2007, 00:41:07

Stoen

avatar

Posts: 1109

Updated to work with more stuff (including those fake buttons and links found on hotmail, yahoo mail and gmail)

middleclickJSOverride.js

Saturday, 26. May 2007, 16:21:11

fearphage

Trained Swordsman of Unwanted Opera Termination

avatar

Posts: 2018

USA

Keep in mind I have not thoroughly looked through the code but one thing has made this unusable for me. There is a call to window.blur and then a call to window.focus right after. What is the purpose of this? I have 'allow lowering of windows' enabled but 'allow raising of windows' disabled. So middle-clicking anything caused my tab to change to a previous tab. I'm not sure if the line numbers are correct exactly but lines 183-184 are the culprits:
    wBlur.call(window);
    wFocus.call(window);

I commented out the call to window.blur and all seems to be well. What is the purpose of refocusing the window? Is it a redraw thing or what?

Saturday, 26. May 2007, 20:51:26

Stoen

avatar

Posts: 1109

Originally posted by fearphage:

I commented out the call to window.blur and all seems to be well. What is the purpose of refocusing the window? Is it a redraw thing or what?


It is to disable panning mode when clicking on buttons and other non-link elements. I would suggest enabling 'allow raising of windows' since this script disables window.focus and window.blur anyway

Updated again.
Fixed some bugs
Removed checkGlobalEventListeners & tryNativeMiddleClick options pending further fixes

middleclickJSOverride.js

Sunday, 27. May 2007, 06:28:35

Stoen

avatar

Posts: 1109

Fixed some more bugs
Removed checkGlobalEventListeners & tryNativeMiddleClick options for good

middleclickJSOverride.js

Sunday, 3. June 2007, 14:59:19

Oh My god thanks a lot I had lost this UserJS and was now desperately looking for it on these forums :S , we badly need a repositery of UserJS....
Anyways, thanks a lot.

Monday, 4. June 2007, 20:34:57

I'm using the following User CSS to prevent myself from middle-clicking javascript links:

a:hover[href^=javascript], a:hover[onclick] {
outline: 2px solid #F80;
}

Monday, 4. June 2007, 21:47:53

Maulkin

French Section Moderator

avatar

Posts: 257

France

What is affecting this code in the user.css? I mean, what are the exact effect?

Friday, 14. September 2007, 13:06:20

Stoen

avatar

Posts: 1109

This works a lot better in Kestrel, but the getter/setter support seems a bit flaky
middleClickJSOverride_O950+.js
For use with Opera 9.5+

Thursday, 4. October 2007, 19:51:55 (edited)

fearphage

Trained Swordsman of Unwanted Opera Termination

avatar

Posts: 2018

USA

This page reloads infinitely while this script is loaded. Can anyone reproduce this behavior? I'm using 64bit xp although I doubt that is relevant.

EDIT: Confirmed indefinitely reloading.

Thursday, 4. October 2007, 21:01:05

AyushJ

avatar

Posts: 4754

That page reloads because of IsParent function which checks the location object of window.top and window and if they're not equal, sets the location of top again:
function IsParent(){if(top.location!=location)top.location.href=document.location.href;}

Friday, 5. October 2007, 23:45:59

Opera 9.23 Build 8808. I just tried it, putting middleclick.js in my directiory for user javascript, making sure that "Allow lowering of windows" is ticked, restarted Opera and even then, instead of opening in a background window, middle click behaved exactly like left click. This is the page where I tested it

http://www.artistdirect.com/nad/store/artist/album/0,,3429896,00.html

What am I missing? Just in case it helps,

http://my.opera.com/community/forums/topic.dml?id=207750&t=1191626824&page=1

Saturday, 6. October 2007, 04:05:44

Stoen

avatar

Posts: 1109

Originally posted by fearphage:

This page reloads infinitely while this script is loaded.


Fixed. Happened because the getter was returning a new fake location object when the location property was accessed.
middleClickJSOverride_O950+.js

Originally posted by Moonbarker Osbourne:

instead of opening in a background window, middle click behaved exactly like left click.


Redownload and try it again
middleclickJSOverride.js

Saturday, 6. October 2007, 17:46:05

Maulkin

French Section Moderator

avatar

Posts: 257

France

Hey, are those 2 lasts scripts similar?

Saturday, 6. October 2007, 21:14:33

Works perfectly now :-) Much thanx! :-)

Sunday, 7. October 2007, 03:05:48

Originally posted by Stoen:

Redownload and try it againmiddleclickJSOverride.js



In the past few hours, I have noiticed a few flaws when it comes to middle clicking on regular links. They are tolerable, but I'm sure that users would rather do without them.

One, when middle clicking on regular links, a blank tab appears for a very brief moment before going to the background.

Two, in testing to make sure it wasn't just some quirk of the site I was on, I opened a blank tab, went to a site that has direct links to image files and middle clicked on them. When I went to close the tab I initally opened, I noticed that the first tab to show was the first pic I opened from that tab instead of the the tab that was opened before I opened a blank tab.

Three, I noticed that when I open a tab with no other tabs open, go to a page, middle click on a few links and then close the tab I opened, The first tab I see is the result of the last one I middle clicked on instead of the first.

Sunday, 7. October 2007, 04:34:34

Stoen

avatar

Posts: 1109

Originally posted by Maulkin:

Hey, are those 2 lasts scripts similar?


They both do the same thing but middleClickJSOverride_O950+.js works better and will only work in Opera 9.5+.
Dont use both, use one or the other.

Originally posted by Moonbarker Osbourne:

In the past few hours, I have noiticed a few flaws when it comes to middle clicking on regular links. They are tolerable, but I'm sure that users would rather do without them.


There is not a lot I can do about it. You can try changing opera:config#UserPrefs|TargetDestination. Setting it to 2 should fix a lot of your quibbles but it will also effect left clicking

Monday, 8. October 2007, 09:41:47

Originally posted by Stoen:

There is not a lot I can do about it. You can try changing opera:config#UserPrefs|TargetDestination. Setting it to 2 should fix a lot of your quibbles



That seems to have done the trick, Thanx! :-)

Originally posted by Stoen:

but it will also effect left clicking



How so? Asking so I'll know what's going on when it does happen

Tuesday, 9. October 2007, 04:22:26

I have noticed that left clicking on links that open in a new tab opens in a background tab, something that's not a bother at all, so I'm not gonna worry about it. What else can I expect?

Tuesday, 9. October 2007, 10:07:35

Stoen

avatar

Posts: 1109

Originally posted by Moonbarker Osbourne:

What else can I expect?


Thats about it.

Tuesday, 9. October 2007, 10:32:01

Stoen

avatar

Posts: 1109

Originally posted by Moonbarker Osbourne:

OK, thanx :-)


No problem mate

Saturday, 20. October 2007, 22:03:33

Maulkin

French Section Moderator

avatar

Posts: 257

France

Is it me or the script doesn't work anymore in the latest Kestrel Alpha aka 9603 build.

Sunday, 19. October 2008, 18:42:04 (edited)

I wouldn't know myself, I have 9.24 full release.

Sunday, 19. October 2008, 18:35:54 (edited)

Stoen

avatar

Posts: 1109

Originally posted by Maulkin:

Is it me or the script doesn't work anymore in the latest Kestrel Alpha aka 9603 build.


Works fine although I updated the script when b9594 was released so try redownloading and trying again.

The reason it keeps on breaking is because of the getters and setters (only used in the 9.50+ versions of the script)
The following snippet of code seems to be broken in b9594+ (throws a "Getter without setter" error)
window.__defineGetter_location;
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

Sunday, 28. October 2007, 13:14:46

Originally posted by Stoen:

Originally posted by fearphage:

I commented out the call to window.blur and all seems to be well. What is the purpose of refocusing the window? Is it a redraw thing or what?


It is to disable panning mode when clicking on buttons and other non-link elements.


Can you use for disable panning mode this script instead of refocusing tab (when i middleclick on normal link)?
2disable middle-click autoscroll.js.js

Saturday, 3. November 2007, 05:32:08

Stoen

avatar

Posts: 1109

Originally posted by mspeedo:

Can you use for disable panning mode this script instead of refocusing tab (when i middleclick on normal link)?


Thats a nice trick 1middleClickJSOverride_O950+.js
But it seems to have a couple of problems:

1) Only seems to work in 9.5+ (not that big a deal for me)
2) Seems to randomly disable middle click scrolling on all tabs not just the one in which the script is loaded, even internal opera: pages and mail from M2. To trigger bug just mash the middle mouse button on an empty area of a page in which the script has been loaded.

Incidentally, what is the problem with using blur?

Saturday, 3. November 2007, 09:45:42

I wanted to disable opening new tab for some miliseconds which then focus back to previous (when i middleclick on normal link), because this irritating me.. i thought that with this script you can do it, i'm not understand javascript .. so thanx for help but normal links always flashing with middleclick :frown: I know that you wrote fix for this "opera:config#UserPrefs|TargetDestination. Setting it to 2" but i'm using 0. sry for bad english

Saturday, 3. November 2007, 11:01:16

Stoen

avatar

Posts: 1109

Originally posted by mspeedo:

normal links always flashing with middleclick


Well I guess we were talking about two different things then. The code you posted will not affect middle clicking normal links. Setting opera:config#UserPrefs|TargetDestination to 2 is the only easy solution

Saturday, 3. November 2007, 12:25:34

AyushJ

avatar

Posts: 4754

Stoen, why don't you middle click the links(like in my snap links or disable middle-click autoscroll) to open in background instead of open().blur ?

Sunday, 4. November 2007, 10:56:04

Stoen

avatar

Posts: 1109

Originally posted by AyushJ:

Stoen, why don't you middle click the links(like in my snap links or disable middle-click autoscroll) to open in background instead of open().blur ?


Lets try...
middleClickJSOverride_O950+.js

Unfortunately disabling the middle click scrolling does not work too well so I have to use blur and focus for that. Now only middle clicking to submit a form will cause the window to 'flicker'

Tuesday, 20. November 2007, 17:05:52

Tyanah

Man Does Not Live On Bread Alone

avatar

Posts: 206

France

It makes some pages reload every time so that Opera only display blank one.

Wednesday, 21. November 2007, 10:37:10

Stoen

avatar

Posts: 1109

Originally posted by Tyanah:

It makes some pages reload every time so that Opera only display blank one.


I'm not a mindreader... URL for the page and the link you are talking about would help :wink:

Monday, 15. September 2008, 22:29:42

iwood

avatar

Posts: 4

Hi.
If you dont like appologies for newbie-ism, scroll to Bold
I am one of these enbetween "user" and "advanced user", that changes all of their advanced settings around, watches the outcome, is able to think what the problem is, but it allways stops there... Not able to change the grounds on wich the trouble stands on. I was hoping some of you could help me, this tread describes one of my wishes, and how to solve them in a very advanced way.

I would really like to be able to use this feature described here, and fixed here, but don't know how to use the .js
Where do I put it to make the new settings work? Is this only for beta-testers?

I also have the urge to open tabs in background, and as this describes that happening, how do I make that happen?

PS:
My laptop has no "midle-click", but I right-click-mouse-down, is this something entirely different altogether when it comes to programming?

Sunday, 19. October 2008, 12:37:16

Stoen

avatar

Posts: 1109

Hello iwood,

To answer your question on how to use UserJS, Lex1 has written up a handy guide/FAQ, which is now a sticky post in this forum. You can find it here
http://my.opera.com/community/forums/topic.dml?id=250627

Originally posted by iwood:

My laptop has no "midle-click", but I right-click-mouse-down, is this something entirely different altogether when it comes to programming?


Yes, there is a difference and this script will only work for middle clicks.
Laptops with no middle-click functionality can generally emulate this by clicking the left and right mouse buttons simultaneously

Anyway, I updated the script to allow left click and hold to open links in the background
http://files.myopera.com/Stoen/files/middleClickJSOverride_O950+.js

Sunday, 19. October 2008, 13:48:53

HaJotKE

Grumbling Hyper-Critical Cantankerous Curmudgeon!

avatar

Banned User

Germany

What's going on here.
There are parts of the thread missing, aren't they? :confused:

Sunday, 19. October 2008, 18:27:27 (edited)

sgunhouse

Volunteer

avatar

Posts: 52730

Flag City, USA

Among other things. I'm set to view the forum at 20 posts per page, this page says "Showing topic replies 41 - 41." Yet there are two replies showing, not 1.

Well, it's consistent. Whatever is in Stoen's post there stops processing of that page. There's only 10 replies on that page, there's no Quick Reply or Forum Jump or anything else below his post. And when I try to edit his post, the edit page stops at a certain point and has no Submit or Preview buttons (hence I can't actually edit that post). Maybe I can trick it?

Sunday, 19. October 2008, 18:40:49

sgunhouse

Volunteer

avatar

Posts: 52730

Flag City, USA

Well, they're back, but I accidentally corrupted Moonbarker Osborne's 1-line post in the process. I'll have to be more careful in the future ...

Sunday, 19. October 2008, 19:22:18

HaJotKE

Grumbling Hyper-Critical Cantankerous Curmudgeon!

avatar

Banned User

Germany

Thanks a lot, Steve... :up:
... that was exactly what happened to me, /Stoen's/ post was the last shown, and no possibility to enter anything.

I had to go to an assumed page 2 to write the above post of mine, but it didn't show either.
Now it's all fine again, M/B some control-character wrecked it. :D

Wednesday, 22. October 2008, 10:07:42

Stoen

avatar

Posts: 1109

Originally posted by dantesoft:

middleClickJSOverride_O950+ v.1.50 seems to interfere with http://www.pctools.com/guides/password/?length=8&phonetic=on&alpha=on&mixedcase=on&numeric=on&nosimilar=on&quantity=5&generate=true



var doc_loc = new String(document.location);
if (window.top.location !== document.location) {
    if (doc_loc.indexOf('google_pack')==-1 && doc_loc.indexOf('privacypolicy')==-1){
        window.top.location.replace(document.location.href);
    }
}

Bah, who uses document.location and why the strict comparison??

Unfortunately I cant use getters or setters to override document.location so the best I can do is make sure similar code wont be affected until you actually click on a link. This should prevent the reload loop that otherwise occurs

v1.51: http://files.myopera.com/Stoen/files/middleClickJSOverride_O950+.js

Wednesday, 22. October 2008, 14:57:12

fearphage

Trained Swordsman of Unwanted Opera Termination

avatar

Posts: 2018

USA

Originally posted by Stoen:

who uses document.location

document.location is used almost as often as window.location from my debugging experience.

Wednesday, 14. January 2009, 05:11:30 (edited)

arnyq

Eat me if you can

avatar

Posts: 165

Canada

Originally posted by Stoen:

Updated to work with more stuff


Thanks for the script. Is it possible to amend it or make a short variant of it that would open a new foreground Tab or Popup Window from a javascript link, which should normally reuse the same Tab or Window?

Example: http://women.brownsshoes.com/eng_ca/Boots . If you select 100 (pictures) per page, that slowly open window will be replaced by an item detail window each time you click on any picture, which is extremely inconvenient. It would be much faster to open a new Tab or Popup (as an option in script) in a variety of similar cases instead of reloading the originating window each time a detail window was looked at.

Also, please provide an option to open it by Shotcut Button + Left Click (or from a RMC Menu, or by holding Left Button long enough) instead of a Middle Click, since many laptops don't have a Middle Mouse Button. When clicked normally, such links should open in a manner designed by that webpage author.

P.S. I've seen a reference to Open-link-in-new-window.js (http://userjs.org/scripts/download/general/enhancements/open-in-new-window.js), but it's site list dependant.

Saturday, 17. January 2009, 06:36:36

Stoen

avatar

Posts: 1109

Originally posted by arnyq:

Example: http://women.brownsshoes.com/eng_ca/Boots


The page uses javascript to submit a hidden form when you click on a link. This script currently only detects form submission when the user middle clicks on specific form elements. Using an event listener would be more accurate but also more troublesome because of the event sequence. Ill look into it, but no promises.

Originally posted by arnyq:

Also, please provide an option to open it by Shotcut Button + Left Click (or from a RMC Menu, or by holding Left Button long enough) instead of a Middle Click, since many laptops don't have a Middle Mouse Button. When clicked normally, such links should open in a manner designed by that webpage author.


I use a laptop as well which is why I already made it so that you can left click and hold to emulate middle clicking.

Forums » Opera Community » General Opera topics » User JavaScript