javascript how to trigger "Alt+E +E" keyboard action - javascript

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.

Related

How to check whether (alt + tab ) is pressed using javascript and how to 1) disable it 2)how to close current browser

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

jQuery - Allow Autoshow Keyboard on Mobile

I have a Rails app that has a closed back-end. On certain pages, I want to auto-select a text input so I can use an external bluetooth scanner to scan a barcode without selecting it with a mouse/touchscreen every time. This works perfectly on non-mobile devices. However, on mobile devices (mostly tablets), I want the keyboard to popup (as the scanners are viewed as "keyboards" by the system). I know this is prevented by iOS, because it could be annoying. However, I want to know:
Can I have the keyboard auto-appear on Android and/or Windows tablets?
On iOS, can I change this default behavior so the keyboard DOES auto-appear? I have access to all the devices this behavior would be needed.
Edit: I know that I can use a click event to make the keyboard appear (that is how it appears now). However, I do not want to touch the tablet every time I want to scan.
There are some workarounds except using great prompt().
Wrap the web application into Phonegap and do the following way.
Keeping in mind that bluetooth scanner needs a first click to enable listening to keyboard events, you can slightly change js-code to perform first click manually (say, fullscreen textarea) and then deal with scanner. It can be a textarea that hides right after a first click and everything is done with javascript without textarea in view.
Looks like Windows smartphones can help you, can't find any issue concerning a problem.
I've tested autofocus fiddle in Chrome56 with Windows 8.1, Windows10 and an old Windows Mobile 8.1 at Nokia Lumia. In first two cases it does listen to keyboard after focusing. The latter one doesn't.
Bonus. HTC One M8 emulator with Android 4.4 listens to keyboard without a click. Tested with browserstack service. What if there are some android examples without need to click?
Bonus2 - autodetect scanner library.
Based on thoses answers you have to try some workarounds
You can't, at least not in iOS (iPhone), and I believe Android as well. It's a usability issue that the keyboard should not be allowed to be triggered except by user input (it's just annoying if it's automatic).
There are a couple of ways I know of to get around this:
prompt() opens the keyboard
If you trigger the .focus() from within a .click() event (e.g. from >opening your dialog), the keyboard shows up
In your case at the openning of your page ?
At least maybe this JS fiddle can help you or this one
You can use JavaScript in built functions for event handling such as focus(), prompt() to initiate bar code scanning function. Also changing some of the usability would also be helpful in this case. For building hybrid apps try some reading on Cordova Keyboard Plugin at https://github.com/cjpearson/cordova-plugin-keyboard
Happy Coding.
try below code. It might work
// div is some selected element
var f = function(event) {
$timeout(function() { // angular way, setTimeout is OK
input[0].focus();
event.preventDefault();
})
};
var mobile = false;
div.on('click', function(event) {
if(mobile) return;
f(event);
});
div.on('touchstart', function(event) {
mobile = true;
f(event);
});
div.on('touchend', function(event) {
event.preventDefault();
event.stopPropagation();
});
My best bet is using offsite input and focusing there. It will help you to control -
the timing of keyboard appearance(setTimeOut)
Check and reopen the keyboard
You will need to do something like this-
<input type="text" style="visibility: hidden; position: fixed; left: -200px" >
With jQuery-
$("#theOffViewBox").focus();
This will work equally on iOS/Android/Windows/Linux as being base JavaScript jugad.

Overriding web application keyboard shortcuts

I think this question is going to be rare, hence enjoyable for some. I have two products - Salesforce's Developer Console & Google Chrome.
Google Chrome has built in hotkey - ctrl + page up/down to switch tab.
Unfortunately Salesforce's Developer Console uses the same hotkey to switch between tabs within console.
Now I will contact Salesforce support and maybe 3-6 months later they will fix the problem. I suppose contacting Google for support is ...
I have tried Shortcut Manager extension for Chrome but it does not have the option to disable the mentioned hotkey.
I was thinking wether it would be possible to overwrite the integer value in keyCode in Salesforce's script?
I've read somewhere that browser Extensions do not have such access. Not sure whether that is true, but then perhaps something like Privoxy could work?
Thank you all.
To enable and customize keyboard shortcuts:
From Setup, click Create | Apps.
Click Edit next to a Salesforce console app.
Click Customize keyboard shortcuts.
Click Edit on the top of the page.
Select Enable keyboard shortcuts.
Edit an existing keyboard shortcut or create a new one:
To edit a shortcut, click Edit next to the shortcut, type the combination of key commands to use, and click OK.
To create a shortcut, click +Add Keyboard Shortcut, type the action the shortcut will perform, a Console Event Name, which is a unique identifier, the combination of key commands to use, and click OK. For the new shortcut to work, you must send the Console Event Name to the developer who defined your shortcut’s action so that he or she can add it to the method that will trigger your shortcut.
To deactivate a shortcut, deselect Active next to the shortcut’s name. You can’t delete the default shortcuts provided by Salesforce, but you can edit or deactivate them.
Click Save.
More info here.

Disable Alt functions (shortcuts) in Google Chrome

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}

What percentage of followed hyperlinks might have their "onclick" JavaScript ignored?

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.

Categories

Resources