# getSelection does not work in iOS - but in Desktop, AnkiDroid, Web versions

**URL:** <https://forums.ankiweb.net/t/getselection-does-not-work-in-ios-but-in-desktop-ankidroid-web-versions/62703>\
**Category:** Card Design\
**Created:** [June 15, 2025, 12:44pm UTC](https://forums.ankiweb.net/t/getselection-does-not-work-in-ios-but-in-desktop-ankidroid-web-versions/62703 "2025-06-15T12:44:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![stablemind](https://avatars.discourse-cdn.com/v4/letter/s/35a633/32.png) [@stablemind](https://forums.ankiweb.net/u/stablemind)\
**Post date:** [June 15, 2025, 12:44pm UTC](https://forums.ankiweb.net/t/getselection-does-not-work-in-ios-but-in-desktop-ankidroid-web-versions/62703/1 "2025-06-15T12:44:17Z")

</div>

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:

```auto
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!

---

<div class="post-metadata">

**Author:** ![Danika\_Dakika](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/danika_dakika/32/17815_2.png) [@Danika\_Dakika](https://forums.ankiweb.net/u/Danika_Dakika)\
**Post date:** [June 16, 2025, 12:16am UTC](https://forums.ankiweb.net/t/getselection-does-not-work-in-ios-but-in-desktop-ankidroid-web-versions/62703/2 "2025-06-16T00:16:15Z")

</div>

Does anything here help you?

> [@You can't use lookup on mac](https://forums.ankiweb.net/t/you-cant-use-lookup-on-mac/10053/2):
>
> You can achieve that with a script. I found this one in one of my templates, though you could try searching for better ones. \<div id="popup-container"\> \<button id="close-popup-btn" onclick="closePopup(true)"\>&times;\</button\> \<a id="open-wiki-btn" href=""\>&#8618;\</a\> \<div id="tc"\>\</div\> \<div id="fadebottom\_v"\>\</div\> \<div id="ic"\>\<img id="popup-image"\>\</div\> \</div\> \<style\> #tc { color: #222222; position:absolute; top: 16px; margin:0px; left:15px; text…

Or in this section of the AnkiMobile manual: [URL Schemes - AnkiMobile Manual](https://docs.ankimobile.net/url-schemes.html) ?

[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.]

---

<div class="post-metadata">

**Author:** ![stablemind](https://avatars.discourse-cdn.com/v4/letter/s/35a633/32.png) [@stablemind](https://forums.ankiweb.net/u/stablemind)\
**Post date:** [June 16, 2025, 11:21am UTC](https://forums.ankiweb.net/t/getselection-does-not-work-in-ios-but-in-desktop-ankidroid-web-versions/62703/3 "2025-06-16T11:21:48Z")

</div>

Thanks for your hint - I’m afraid I have not made myself clear enough.  
Calling a URL and passing on values is not a problem.

My problem is retrieving selected text in cards in the iOS app. JavaScript `window.getSelection()`appears not work in Anki Mobile on iPhones.

---

<div class="post-metadata">

**Author:** ![Anon\_0000](https://avatars.discourse-cdn.com/v4/letter/a/c67d28/32.png) [@Anon\_0000](https://forums.ankiweb.net/u/Anon_0000)\
**Post date:** [June 16, 2025, 11:35am UTC](https://forums.ankiweb.net/t/getselection-does-not-work-in-ios-but-in-desktop-ankidroid-web-versions/62703/4 "2025-06-16T11:35:56Z")

</div>

It seems to be a known issue with iOS. Maybe try the solutions posted by other people, e.g. see:

1. [IOS 15, javascript functions windo… | Apple Developer Forums](https://developer.apple.com/forums/thread/690918)
2. [window.getSelection() doesn't work in iOS 15 · Issue #14270 · mdn/browser-compat-data · GitHub](https://github.com/mdn/browser-compat-data/issues/14270)

---

<div class="post-metadata">

**Author:** ![stablemind](https://avatars.discourse-cdn.com/v4/letter/s/35a633/32.png) [@stablemind](https://forums.ankiweb.net/u/stablemind)\
**Post date:** [June 16, 2025, 2:51pm UTC](https://forums.ankiweb.net/t/getselection-does-not-work-in-ios-but-in-desktop-ankidroid-web-versions/62703/5 "2025-06-16T14:51:39Z")

</div>

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](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).  
😀

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex002/uploads/anki2/original/1X/8f1279ababc5879d54e4838989f606cfe55af8c7.jpeg) [@system](https://forums.ankiweb.net/u/system)\
**Post date:** [July 16, 2025, 2:51pm UTC](https://forums.ankiweb.net/t/getselection-does-not-work-in-ios-but-in-desktop-ankidroid-web-versions/62703/6 "2025-07-16T14:51:46Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
