I want to focus on my browser's previous tabs, so i want to trigger browser tab by triggering key-code. How to do this thing using key code.(and i don't find any keycode for "ctrl+pageup")
That ain't possible.
You can't trigger OS/Browser functions like keypresses from JavaScript.
If this were possible, imagine the problems it would cause by:
sites making you save stuff. (Ctrl+S -> Enter)
sites making you close things. (Alt+F4)
sites making you open new tabs. (Ctrl+T)
etc.
You can only simulate these keypresses within the page's JS.
Related
I am very confuse and not sure either javascript or jquery can trigger keyboard event like Shift+Q or Alt+Q from button click. I already looking on this forum and also download some of js file like key-event.js and crossBrowser_initKeyboardEvent.js but I still cannot get a result what I want.
My situation is I need to trigger ALT+q key from button html. This should be automatically proceed and will be effect not only inside html(browser) but also on desktop client.
Thanks you.
The effects of keyboard and mouse events fired by Javascript within a web pages are limited to the contents of those web pages. These events cannot reach outside of the web page to trigger keyboard shortcuts in the browser or desktop.
I read these two questions:
How can I detect browser tab refresh or close using javascript
and
How do I detect a page refresh using jquery?
which suggest binding to 'onbeforeunload' and also binding on F5 and Ctrl-R key presses, which is good advice.
However, most browsers have a refresh button on their address bars, like this in Chrome:
Question is: is it possible to detect and bind to refresh event of browser's address bar's refresh button?
By binding onbeforeunload to windowlike this window.onbeforeunload it should trigger in most browsers. check this fiddle. It seems it's not supported on IOS devices.
For IOS apple docs suggest using pagehide see apple page on Handling Events.
The load and unload events may not work as expected for back and forward optimization. Use the pageshow and pagehide events instead.
Keep in mind that this will also trigger on all other kinds of navigation away from the page. Such as close, tab close, back/ forward navigation, link navigation and address bar navigation
Checking if the browser is reloading versus navigating away from the page I'm pretty confident is not possible, due to security/ privacy reasons not being able to give you the destination url. You could eliminate link presses by using it is an condition when firing the onbeforeunload.
Edit: If you need to check if the page has been reloaded however, you could use sessionvariables or cookies to store that the user has already opened the page once before.
How to use JavaScript to detect user operations on browsers such as click backward/forward/refresh button, keyboard inputs in navigation bar or search bar of FireFox, as well as any hotkeys for these operations.
You can't. Anything that happens outside the page content area is completely off-limits to scripting. (Thank God... it would be a security and usability disaster.)
About the only information you can get is that if an unload event happens without a link being clicked/form submitted, the user did some kind of navigation outside the page (such as window close, bookmark open, address entered, back/forward/etc). And if you really want to be obnoxious you can detect/prevent browser-specific navigation keystrokes like F5-for-refresh when the focus is in the window.
Well, for mouse/keyboard events on the page's DOM or the window, you can detect. The easiest way for me is using JQuery's event: http://docs.jquery.com/Events
Anything else e.g clicks on the browser toolbars/search boxes/3rd party components will be highly unlikely (I'm hesistant to say 100%).
Navigation of pages/url can be detected as well but not necessarily identified as back/forward or refresh.
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.
I want to implement keyboard shortcuts using jQuery.
Specifically, I want to fire an event when e.g. F5 is clicked.
What kind of issues do you run into with keyboard shortcuts?
Also, any online chart that has all the keyboard mappings to numbers?
You can't and shouldn't use F5 key - it's reserved by most browsers as refresh, and even you could you shouldn't want to confuse users by breaking UI conventions
You can use this little app to find out key codes
This little JS library will let you do it:
http://www.openjs.com/scripts/events/keyboard_shortcuts/
however there are some things to note.
1.) In IE, you can't AFAIK stop the event, you are just hooking in before it refreshes
2.) In IE, certain keyboard events you simply can't intercept... e.g. CTRL+S will always bring up the Save dialog, like it or not.