使用Javascript在Mobile Safari中获取所选文本 [英] Use Javascript to get selected text in Mobile Safari

查看:90
本文介绍了使用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)

这篇关于使用Javascript在Mobile Safari中获取所选文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆