ContentEditable element does not react on hotkeys [duplicate] - javascript

I'm developing a Chrome extension that injects JS code into all opened tabs. The task of this code includes displaying a textbox, implemented as a contentEditable <div> to allow formatting. However, the contentEditable element doesn't play well with some websites, e.g. Twitter.
Try it yourself:
Go to twitter.com
Paste javascript:document.body.setAttribute('contentEditable', true); in the address bar and hit enter.
Click anywhere in the document - you should now be able to edit the text.
Try typing a j or k. You will see: The character does not appear, instead, the selection is moved (a tweet in the list will be highlighted).
I have tried hard to find out how Twitter's keyboard navigation is implemented, but could not find any hints. Can you give me any tips on how to solve this problem (and avoid similar problems on other websites)?
Using an iFrame for the input triggers some other, very weird bugs, so I want to avoid that if it's possible.

Please make sure you don't have installed vim keyboard extension on google chrome.
J and K are then used for navigation shortcuts. (up/down).

Related

How to select text on chrome DOM with cursor and access it on chrome extension

This question is a bit confusing and I am sorry I do not have any code to provide. I am just interested in knowing if this is generally possible or if it is a limitation of chrome extensions.
Currently, I am thinking of building a chrome extension which should have a "Manual Select button". When this button is clicked, users should be able to highlight (or select) text on the Chrome DOM using their cursor. The text they highlight or select should then be saved and displayed in the Chrome extension (I am guessing I will put that in local storage or something). The problem I am facing with this idea, is that I notice Chrome extensions close when you click away meaning the text you select will not be saved in the Chrome extension. Is there any way to force the extension to stay open even if you click away? Or, is there a way to have the extension still run the button's function logic while it is closed?
If this is possible and can provide some sudo code of how this would work it is greatly appreciated!

Enable text selection on a website using JavaScript

I know that typing
javascript:void(document.oncontextmenu=null) allows users to enable right click on a webpage
and javascript:void(document.onselectstart=null) should enable text selection if i'm correct?
but I tried typing these on http://www.pcworld.co.uk/gbuk/laptops-netbooks/laptops/apple-laptops/apple-macbook-pro-15-with-retina-display-21576115-pdt.html and it won't work.
by the way I typed it in the console of Google Chrome browser.
#Pointy pointed out that text selection worked fine for him. I tried in a few browsers - in Google Chrome specifically, on mouse down, the cursor changes when one tries to select text on a particular part of the page, and it does not allow this. However, on Firefox, you are perfectly capable of selecting the text.
For your intents, use a different browser and select the text.
For all we know, that sight could have custom javascript and logic preventing text selection, though its pretty lame that it doesn't work cross browser. But this custom logic is probably why your above mentioned commands aren't working.

Unable to trigger keyboard on input focus through JavaScript

I'm developing an web application that contains a form with two input elements. One of the user requirements is that after inserting a character into the first input it should automatically trigger the focus of the next element and show the keyboard.
After googling about it seems that isn't possible to programatically trigger the keyboard on iOS through JavaScript. The reason however isn't quite clear to me, some say that is an UX feature but I can't find any official information about it.
So my question is, where can I find some official specs that explain the technical reasons whereby this isn't possible?
Official specs:
http://developer.apple.com/library/IOs/#documentation/AppleApplications/Reference/SafariWebContent/Introduction/Introduction.html#//apple_ref/doc/uid/TP40002079-SW1
Unfortunately, the official specs will not answer your question.
Generally, with forms on iOS safari, the keyboard will stay open until the user chooses to close it. When you auto-focus the next form input, does it close the keyboard?

disable onclick ads with a content-script in Google Chrome

There are some video streaming sites that pop up an ad anytime you click anywhere on the page. The problem is, you have to click on the page to press play! So I was thinking of making a UserScript that disables the script that does this. The only problem is, I already disable all the scripts on the site and when I do it still pops up. Is there a way that I can disable them ? I'm also using jQuery, so if I can do it through their interface, that would be great.
edit: Two perfect examples of such sites are daclips.in and gorrilavid.in
I have Adblocker Plus, and it seems like it is not recognizing "on Click" events as pop-ups, rather normal clicked links. And the logic is simple, no Adblocker will block you from clicking something intentionally and it (the link) opening in another window/tab.
The problem is the new window contains your clicked Url, while the original window/tab "Refreshes" (i.e. redirects) to another url.
Advertising companies seem to use this trick to bypass adblocking software.
Just ditch Chrome and use Firefox. Firefox already have built-in mouse-click popups. I think all addons like Adguard or Adblock can not disable mouse-click popups. If you use Firefox, these are the steps:
Type about:config in the browser's address bar and hit the enter key.
First time users need to confirm that they be careful on the next page.
Type or paste dom.popup_allowed_events into the search field.
The value of the preference highlights all events that are allowed to spawn popups.
Edit the value to remove some or all of the items here.
Why not just use a browser extension such as AdBlock?
https://chrome.google.com/webstore/detail/adblock/gighmmpiobklfepjocnamgkkbiglidom?hl=en
My go-to is right click and open in new tab. onClick events only happen with a left click. It's cumbersome but it still ends up being less work than closing the pop-up and whatever annoying prompts it may have.
I do not there's a practical solution for this.
Moreover, I think some of the answers here are missing the specific case in OP, where clicking anywhere on the page will cause the pop up to happen, not just clicking on links. According to this, neither right-clicking then choosing "open", nor noticing and blocking the target URL will help. I do not know of an add blocker that helps here either, because it's not trivial to meaningfully filter a click event that is taking place on the whole page object.
Only the solution provided by #Monkey would work, at the drawback of possibly breaking other things.

Why does InDesign lose all keyboard ability if a scriptUI palette is open?

Salvete! I have a simple InDesign script to display a palette window. Problem is, when I display this window, or any other scriptui palette, InDesign loses all keyboard focus - I just can't type anything. It's as if the script palette eats all my keyboard input.
Here is the most simple script:
#targetengine session; //I have tried without this line, too.
var PaletteWindow = new Window('palette', "Test");
PaletteWindow.show();
Am I missing something? Has anyone else seen this problem?
I am using InDesign CS4 on XP Pro SP3; Dell Precision T3400 with Core Duo; 4mb of RAM.
Here is the link to my post at InDesignSecrets:
http://indesignsecrets.com/forum/indesign-add-ons-scripts-scripting-and-plug-ins/scriptui-palette-breaks-keyboard#p8419
Ah, I figured I could answer my own question after four months. This link is to a thread with the same problem where the palettes steal keyboard focus. It does not contain a definitive solution, but does offer a workaround:
http://forums.adobe.com/thread/288782?start=0&tstart=0
Here is another workaround:
Since the palette is supposed to "do something" and then return focus to IND, then add:
app.activate();
to the function call for the button. That way, after you push the button, you can work normally in IND.
This works fine, except that anytime you move the mouse over the palette, it sets focus to the application. This solution is a workaround for CS4.
[update]
Now I am using CS5, and I find that it is no longer necessary to do this. It seems the problem was a bug in the CS4 UI scripting interface.

Categories