问题描述
我有一个 iOS 应用程序,它只有一个视图,即 UIWebView(它打开应用程序的主要内容).我希望当我在某处(例如在表格行上)单击应用程序以在 Safari 浏览器中打开特定链接,而不是在 UIWebView 内.
I have an iOS app which has only one view and that is UIWebView (It opens the main content of the app). I would like when I make a click somewhere(e.g on a table row) the app to opens specific link in Safari browser not inside the UIWebView.
这是否可行,无需编写任何 iOS 代码,而是让 JavaScript 在 Safari 本身中打开该链接?
Is that doable without writing any iOS code and instead of that make the JavaScript opens that link in Safari itself ?
我有那个代码,但它根本没有帮助:
I have thatcode,but it doesn't help at all:
HTML 代码
<tr class="link-to-pdf" data-href='www.example.com'>
JS 代码:
$(".link-to-pdf").click(function () {
var a = document.createElement('a');
a.setAttribute("href", this.getAttribute("data-href"));
a.setAttribute("target", "_blank");
var dispatch = document.createEvent("HTMLEvents");
dispatch.initEvent("click", true, true);
a.dispatchEvent(dispatch);
});
推荐答案
在某些情况下,您可以告诉 javascript 中所有具有 target="_blank" 的链接,并将它们传递给 window.使用_system"参数打开.这适用于 iOS 和 Android.
In some cases, you can tell all links in your javascript that have target="_blank", and pass them to window.open with the '_system' param. This will work on both iOS and Android.
$(document).on('click', 'a[target="_blank"]', function(ev) {
var url;
ev.preventDefault();
url = $(this).attr('href');
window.open(url, '_system');
});
或者在您的情况下,只需将 a.setAttribute("target", "_blank"); 替换为 a.setAttribute("target", "_system");
Or in your case, simply replace a.setAttribute("target", "_blank"); with a.setAttribute("target", "_system");
这在一个古老的项目中对我有用,但我不确定它是否仍然有效(在 iOS 和 Android 上)
This worked for me in an ancient projekt, but im unsure if it still works (on iOS and Android)
这篇关于iOS UIWebView 应用在 Safari 中打开链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)