I use the following code (as shortcut) to redirect users on my feedback page.
<a href='/feedback/' accesskey='f'>feedback</a>
But this code does not work in Google Chrome because when user presses Alt + F it will open the Google Chrome menu bar.
How do I disable those 'shortcuts'?
It can be jQuery, javascript...
Note: I have written a javascript code that redirects, but it firstly opens the Chrome menu bar then does its job.
Browsers that allow this theoretically expose a security vulnerability. If it's possible to override "system" behaviors, you could hijack the users browser. It would be able to pop up a fake "File" menu that simulates the real one and makes the user think they are interacting with their own local machine instead of a web site.
Because of this it's impossible in most modern browsers.
There are certain special keys that are reserved and Alt+F is one of them but it will really vary between browsers and operating systems. Here's a good article.
In Google Chrome (tested in V44), the modifier key to access accesskey keyboard shortcuts is Alt.
However, if the key conflicts with a browser shortcut, it is accessed with AltShift. So the solution you posted works, but only using AltShift.
Example:
the first link is accessed with AltShift+f (conflict with menu shortcut)
the second link is accessed with Alt+a (no conflict)
<h1>Links with accesskey attribute</h1>
<a href='http://www.example.org/' accesskey='f'>
Link to www.example.org (accesskey: f)
</a>
<p/>
<a href='http://apache.org/' accesskey='a'>
Link to apache.org (accesskey: a)
</a>
Incidentally, I prefer the solution Firefox uses, which is to always use AltShift for these shortcuts. This is more consistent for users than Chrome's behavior (though the Chome devs may have had their reasons).
Note: The above is valid on Windows and Linux. AFAIK, Chrome on Mac OS X uses different shortcuts.
As others have stated, it's probably not a good idea.
But if you're a madlad and you like doing what you want, this will actually work:
document.addEventListener('keydown', (e) => {
e.preventDefault();
if (e.altKey) {
console.log('yay');
}
})
e.preventDefault() needs to be placed at the top of the event handler. This prevents the browser's default behavior (ie., opening menus).
I just found a way how to disable browser functions when user presses Alt + other button. Javascript can disable this shortcuts by writing at the end of the function return false
Example
function function1(){/* code goes here */; return false}
Related
So with the most recent Facebook phishing scandal1, Google Chrome (and, I assume, other browsers) disabled the ability to paste javascript directly into your URL bar. Well, it still lets you, but it strips the javascript: part.
I'm trying to find a work around to be able to directly paste javascript into the URL. Test it out for yourself:
javascript: alert('Hello World');
instantly (for me at least) strips the "javascript:" part of the code only in Google Chrome.
1 Facebook Phishing Scandal - It's when people where copy-paste that JavaScript code into their URL and it'd invite all their friends to an event OR post something malicious on every friend's wall.
Next best thing workaround: Leave out the leading j when copying the snippet and add only that character manually:
mark (w/ mouse) from avascript:…
Ctrl+C
Ctrl+L
j
Ctrl+V
Enter
When coding a little yourself, you may find yourself needing to frequently prepend javascript: into the address bar.
Here are two ways to speed this up:
Add a search engine keyword entry with the keyword j and the URL javascript:%s.
Then you can do:
Ctrl+L
j
Space
Ctrl+V
(It also works like a charm, when you already have JS code in the address bar:
Home
j
Space
)
Autocompletion can save you a few keystrokes, if you don't want to create a search engine keyword entry.
It requires a quick preparation: Feed javascript into the address bar:
Ctrl+L
javascript
Enter
From then on, this shortcut is available:
Ctrl+L
j
(javascript should be proposed as completion. Otherwise repeat submitting javascript in the address bar, until your browser promotes it to default completion for j.)
End
:
Ctrl+V
Yes. Use normal developer console.
So with the most recent facebook phishing scandal, google chrome(and i
assume other browsers) disabled the ability to paste javascript
directly into your URL bar. Well it still lets you, but it strips the
"javascript: " part.
IE9 and FF added this "protection" too... only Opera holds, for now.
Still, it became even easier. Just trick your user to paste code into console. Same effect as with old snippets.
It is so in any version of Chrome. As I think they are trying to protect you from execution of dangerous code. There are some ways of solving it:
Paste then type javascript: by hand
Press F12, open console and execute the code (without javascript:) from there
Add javascript link to favourites and execute just by clicking
Make an extension or use some suitable one
Simply bookmark the bookmarklet (that's the term for javascript:...). Create an anchor which links to the bookmarklet, and ask the user to bookmark this link.
Example:
Bookmark this by dragging it on your bookmark bar
I've just tested it in FF7, and it works like a charm.
I want to check whether (alt + tab) is pressed or not if pressed then I want (1) how to close present browser
2) how to disable (alt+tab)
You probably can't detect that it's been pressed,¹ and you can't cancel it — nor should you be able to. The user's workstation is theirs, not yours. Separately, it's mostly pointless (for instance, to prevent cheating during an online exam) in this age of people with multiple internet-connected devices.
Administering remote tests is a hard problem that I suspect hasn't been solved yet. It will not be solved by trying to lock users into the browser.
¹ A quick test using the keydown event, for instance, didn't even fire the event on my workstation. Alt+Tab to switch between applications is handled at a lower level than the browser.
It's possible, there are some examples:
You can create a desktop app using something like electron
Solution: Disable keyboard shortcuts Alt + Tab in electron application
Check out Page Visibility API (probably it's what you want to achieve) https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API
I need to access Safari Menu options to reset browser settings. How to achieve this using Javascript.
Manual Actions are as follows
ALT + E + E
click Tab (10 times)
Click on Enter button
I'm afraid Safari isn't going to provide such API for JS at least for security reasons. I think it may be possible in Safari extensions.
When creating webapps, is there any guidelines on which keys you can use for your own hotkeys without overriding too many of the browsers default hotkeys.
For example I might want to have a custom copy command for copying entire sets of data that only makes sense for my program instead of just text. The logical combination for this would be Ctrl + C but that would destroy the default copy hotkey for normal text.
One solution I was thinking about is to only catch the hotkey when it "makes sense" but when you use some advanced custom selection it might be hard to differentiate if your data is focused, if text is selected or both.
Right now I am only using single keys as the hotkey, so just C for the example above and this seems to be what most other sites are doing too. The problem is that if you have text input this doesn't work so good. Is this the best solution?
To clarify I'm talking about advanced webapps that behave more like normal programs and not just some website presenting information(even though I think these guidlines would be valid for both cases). So for the copy example it might not be a big deal if you can't copy the text in the menu but when Ctrl + Tab, Alt + D or Ctrl + E doesn't work I would be really pissed, cough flash cough.
I think 85 Firefox Shortcuts for Mac and PC, Keyboard Shortcuts for the Opera Browser, Chrome's Keyboard and mouse shortcuts, Safari: Browser Window and Menu Shortcuts and Internet Explorer keyboard shortcuts may be helpful (other browser's hotkeys are similar). But always bear in mind that installed extensions can define their own hotkeys (e.g., I like Firebug's F12 a lot).
How about using Shift + ?.
I don't think it will override any important option (am I wrong?)
As far as I know all popular web browsers execute the onclick attribute of an anchor link first, then follow the path specified by the href attribute.
The problem here is that the onclick attribute only gets called when clicking with the left mousebutton (without pressing ctrl or shift for a new tab or window) or when pressing enter on your keyboard while the tabIndex is set to the link you want to follow.
But there are many other ways of following a link than just those two.
Ctrl + click
shift + click
rightmousebutton + open
rightmousebutton + new tab
drag & drop link to address bar
and so on...
My client uses onclick for conversion statistics. Which seems heavily unreliable.
My question:
What percentage of hyperlinks are being followed without activating their onclick attribute?
All estimates are highly appreciated. I'm completely lost; I think it can be any number...
Aside from those of us who habitually middle-click/ctrl-click to open links in new tabs, there's another major cause of onClick failure: NoScript and similar plugins which allow javascript to run only when it comes from whitelisted sites. If your domain isn't on my whitelist, then your onClick won't run, no matter how I trigger the link.
If you want reliable stats on which pages people are visiting, there's only one bulletproof source for that: The web server logs.
The logs are probably also your best bet for tracking how people move throughout the site, but they're not entirely reliable, as some privacy-paranoid users will falsify their referer headers or just not send them at all, but I expect that to be far less common than disabling javascript.
It depends. If the audience is more technically inclined, I'd assume that using alternative ways of following a link would be more common. All in all, though, even a lot of technical people seem to be unaware of things like clicking the middle mouse button to open or close a tab. If that's the case with technical people, I wouldn't be surprised if almost no one in the general audience used it.
The links are all exit-links. I was thinking of a PHP script that does the counting of clicks.
Though this is not the subject of your question, you might want to have a look at Google Analytics then. They are The Master in tracking you. They track right-clicks (even when not actually selecting "open in new window" after that, which they obviously cannot know), which will yield Ajax calls to http://www.google.com/url.
To see Analytics in action: with Adblock and the like disabled, search something on google.com and open up Live HTTP Headers in Firefox (or your Firebug Net tab in Firefox, or WebKit's Resources pane in Safari or Chrome, sorted by time). Next, click, right-click, shift-click or control-click any search result (preferably a result that does not require a lot of HTTP traffic by itself, or is in your browser's cache).
the onclick attribute only gets called when clicking with the left
mousebutton (without pressing ctrl or shift for a new tab or window)
Not entirely true. I created a quick test at JS Bin, to show that modifier keys do not affect the onclick event. (For right-click, one should use the oncontextmenu event.)
What are you doing in your onclick handler that you are worried about not working? e.g. if you have a regular link to a page... and the onclick just opens that same page in a pre-sized popup for user convenience in a web application... then there's likely no issue (e.g. CTRL+Click) still opens the page, it just gets opened in a new tab)
If you are just trying to "log" every click in the site/application for tracking purposes then maybe you can hook into the onmousedown/up or focus/blur events instead/also.