I created a card template with some JavaScript years ago. It checks for selected text and passes it on to a website. It has worked and is still working in a) the desktop version, b) AnkiDroid and c) the Web version. However, I recently got an iPhone (with iOS 18.5) - and the selection cannot be retrieved in the AnkiMobile app.
The relevant code snippet is this:
wort = "";
if (window.getSelection()) {
if (window.getSelection().toString().length > 0){
wort = window.getSelection().toString().trim();
}
}
window.getSelection() is true, but window.getSelection().toString() returns nothing, so wort remains an empty string.
As written above - coding unchanged for years, but not working in the iOS app.
If anyone has an idea (or even a solution) it would be great!
Thanks!
[And I’m just taking a flyer that they might – I actually have no idea. But it might give you some things to try until someone more knowledgeable is available.]
Thank you so much!
The problem appears to be the popup menu (“Copy … Translate … Share …”) that automatically comes up as soon as you select text on the iPhone.
I found a nice solution in the second link (https://github.com/mdn/browser-compat-data/issues/14270) suggested by Anon_0000 that constantly checks if the selection is being changed and saves the currently selected text in a global variable - before the popup comes in.
This has worked for me on all versions (desktop, Web, Android and now also iOS).