Skip to content
Advertisement

Get selection from Google Docs

Is there a way around the fact that

window.getSelection()

does not seem to work in Google Docs? I want to capture text from a highlighted selection from Google Docs. My implementation is with Chrome Extensions, but that is not as relevant as the fact that window.getSelection() doesn’t seem to work there (though it does elsewhere).

Thanks!

Advertisement

Answer

As mentioned on Docs Blog – What’s different about the new Google Docs?, Google Docs eschews the browser’s native capabilities and implements everything — including text formatting and positioning, cursor movement, and selection handling — in its own Javascript.

Since Docs doesn’t provide a public in-browser API to the document currently being edited, you’ll either have to dig through its private innards or give up.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement