在webview中从远程URL获取URL并在Safari中打开它 [英] Get URL from remote URL in webview and open it in safari
问题描述
我在我的应用程序中有一个webview,我也有一个在线的网站。我在我的webview中加载了我的网站,当我按下我网站上的链接时,我想在Safari中打开该链接,而不是在我的webview中,这里是我所做的。
我有我的webview:
var webview = Titanium.UI.createWebView({
url:' http://www.TEST.com',//虚拟url现在
顶部:42,
剩下:0,
宽度:310,
高度:275
});
我的HTML档案(我会放在网路上,所以我只会透过我的网址存取):
<!DOCTYPE html>
< html lang =en>
< head>
< meta charset =utf-8>
< link rel =stylesheethref =style.css>
< link rel =stylesheethref =img.css>
< script src =http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js>< / script>
< script src =script.js>< / script>
< / head>
< body onload =Ti.API.info('body loaded!');>
< div id =wrapper>
< ul class =slideid =slideOne>
< li>< img src =images / 1.jpgonClick =Ti.App.fireEvent('openlink',{url:'http://www.google.com'}) />< /锂>
< / div>
< / body>
< / html>
访问HTML代码我有以下代码::
Ti.App.addEventListener('openlink',function(e){
alert('Ti.App);
Ti.Platform .openURL(e.url);
});
但是当我按下图片时没有任何反应,任何人都知道为什么?
您无法在远程网站上执行此操作。 从本指南中,在远程网站内容 em> section:
您不能在从远程主机加载的HTML内容中使用任何Titanium语句。
I have a webview in my application and I also have a website online. I have loaded my website in my webview and when I press a link in my website I want to open that link in Safari and not in my webview, here´s what I have done.
I have my webview:
var webview = Titanium.UI.createWebView({
url: 'http://www.TEST.com', // dummy url now
top: 42,
left: 0,
width: 310,
height: 275
});
My HTML file (which I will put online so I will only access it trough my www address):
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="img.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="script.js"></script>
</head>
<body onload="Ti.API.info('body loaded!');">
<div id="wrapper">
<ul class="slide" id="slideOne">
<li><img src="images/1.jpg" onClick="Ti.App.fireEvent('openlink',{url:'http://www.google.com'})"/></li>
</div>
</body>
</html>
And to access the HTML code I have the following code::
Ti.App.addEventListener('openlink', function(e) {
alert('Ti.App);
Ti.Platform.openURL(e.url);
});
But nothing happens when I press the image, anyone has a clue why?
You cant do this on a remote web site.
From this guide, in the Remote web content section:
You cannot use any Titanium statements within HTML content loaded from a remote host.
这篇关于在webview中从远程URL获取URL并在Safari中打开它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!