IOS 15, javascript functions window.getSelection() or document.getSelection() not working

Hi we do have a functionality where we need to highlight some content. Our functionality was using javascript functions window.getSelection() or document.getSelection(). These were working fine with IOS 14. when our devices were updated to IOS 15, we are getting null for either window.getSelection() or document.getSelection(). Could you please help us to resolve this issue?

we appreciate your help.

Same for me with Safari 14 and iOS 13. Hoping to get an answer soon!

Anyone can help, I think this function is basic, don't know why Apple stop to support it.

am also facing same issue , have you got any alternative solution.

same issue here. window.getSelection nor document.getSelection works on ios 16.2. According to the docs it should be supported but it clearly isnt working. Either update the docs or give us an answer.

https://developer.apple.com/documentation/webkitjs/document/1630421-getselection

It was very hard to find the solution for this, as I had some problems in an application that required to get the selected text from the user, and the only devices we were having troubles were iOS devices (any browsers). So, googling about it, I came across bunch of Apple forums, until I found this issue and its correspondent JSFiddle (https://jsfiddle.net/JasonMore/gWZfb).

When I tested in my iPad in a localhost quick test, it worked perfectly.

It would be really great if Apple exposed it somehow or even better, if we did not have to deal with this kind of approaches to get a simple selection from the user.

Hope I have helped somehow.

window.getSelection() actually works fine. The problem here is because when the focus is lost, then the selection is cleared as well.

I forgot which version in ios i had this working before but now that i checked again under v16.1, it doesnt work. window.getSelection().rangeCount is always zero when i click a button to do some code with the text selection.

IOS 15, javascript functions window.getSelection() or document.getSelection() not working
 
 
Q