使用Javascript在Mobile Safari中获取所选文本

问题描述:

所以我正在制作一个书签,我最好使用循环抓取用户选择的内容。 window.getSelection和document.getSelection都是我可以调用的函数,但是,它们总是返回一个空字符串。

So I'm working on a bookmarklet where it would be ideal for me to grab the content selected by the user using the "loop". Both window.getSelection and document.getSelection are functions that I can call, however, they always return an empty string.

我认为问题是当你点击时移动Safari中的书签图标,选择已发布。例如,如果您选择某些文字,请点按+,书签或其他标签,即使您取消也不会选择此选项。

I believe the problem is that when you tap on the bookmark icon in Mobile Safari, the selection is released. For example, if you select some text, tap the "+", bookmark or other tab, the selection is unselected even if you cancel.

是否有任何想法,如果它是有可能获得这些数据吗?或者这几乎是不可能的?

Any thoughts on if it is possible to get at this data at all? Or is this pretty much impossible?

循环的内容在移动浏览器中没有暴露给javascript,期间。所以这是不可能的(我假设您在完整的浏览器中工作,而不是在启动保存到主页图标时创建的浏览器窗口中)

The contents of the "loop" are not exposed to javascript in the mobile browser, period. So this is impossible (I am assuming that you are working in the full browser, not in the browser window created when you launch a "saved to home page" icon)