Titanium Webview - 单击链接时转到默认浏览器
在 Titan 中,我使用 WebView 来显示 WordPress 博客页面,该页面已经针对移动浏览器进行了格式化。这是一个很好的解决方法,而不是编写我自己的界面。应用程序的唯一焦点不是浏览器。
但我的问题在于,当用户单击初始显示域之外的链接时。我只希望主域显示在应用程序浏览器中。如果单击任何其他链接,这会将用户带到该域之外,我希望在手机默认浏览器中打开它。
谁能给我指出这个方向。我尝试添加一个侦听器来尝试捕获链接点击,但是,我没有成功。
谢谢
in titanium, i'm using the webview to display a wordpress blog page, that is already formatted for mobile browser. instead of writing my own interface, this works as a good work around. the apps sole focus isn't the browser.
but my issue lies, when the user clicks a link outside of the initial displayed domain. i only want the main domain to be displayed in the apps browser. if any other link is clicked, that takes the user outside of that domain, i want to have it open in the phones default browser.
can anyone point me in a direction for this. i tried adding a listener to try and catch link clicks, however, i've been unsuccessful.
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在这篇博文中,我展示了如何查找网页中的链接并更改链接行为。使用相同的方法,您可以拦截链接并重定向到在设备默认浏览器中打开该 URL
in this blog posting I show how to find links in a webpage and change the link behavior. Using the same method, you can intercept the links and redirect to opening the URL in the devices default browser
一种解决方案是通过 WebView(您的博客代码)内的 Javascript 捕获 onclick() 事件,并通过自定义处理程序处理该事件。也许您可以通过 Titanium 将 javascript 事件处理程序代码注入到正在运行的 WebView 中。
另一个解决方案是让您的博客文章对于应用程序技术来说是可读的,并创建一个新的数据接口。这就是我要做的。为此,我将使用某种 JSON 数据格式和简单的 REST 接口来获取数据。
我认为上述解决方案都没有那么简单。如果你想要一个“感觉很棒”的应用程序,你就必须自己处理事件。也许 Phonegap 会是一个更好的解决方案 4 你的问题。但您仍然需要一种用于博客数据的 REST/JSON 接口。应用程序背后的想法是,主要代码位于您的应用程序中,并且您从远程源获取内容。这样,与简单的浏览器优化网站相比,您将获得优势。
One solution would be to catch the onclick() Event by Javascript inside the WebView (your blog code) and handle this by a custom handler. Maybe you can inject the javascript event handler code into the running WebView through Titanium.
Another solution is to make your blogposts readable for app technology and create a new data interface. This is the way I would do. For that I would use some kind of JSON data format and a simple REST Interface to get the data.
I don't think bove solutions are that simple. If you want an app with "great feeling", you'll have to handle the events by your own. Maybe Phonegap would be a better solution four your problem. But there you will still need a kind of REST/JSON interface for your blog data. The idea behind an app is, that the main code is in your app and you get the content from a remote source. This way you'll get an advantage compared to a simple browser optimized site.