iOS应用程序jQuery Mobile网站-仅在本机iPhone应用程序中查看过页面时,才包括JS文件 [英] iOS App & jQuery Mobile Site - Include JS file ONLY if page is viewed in native iPhone app

查看:93
本文介绍了iOS应用程序jQuery Mobile网站-仅在本机iPhone应用程序中查看过页面时,才包括JS文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用jQuery Mobile构建的移动网站.我目前正在设计一个带有单个webView的iOS本机应用程序,以显示此移动网站.

I have a mobile website built using jQuery Mobile. I am currently designing an iOS native app with a single webView to display this mobile website.

问题:

如果在普通的移动浏览器中查看了jQuery移动网页,我希望所有人都能正常工作.但是,如果使用我正在设计的iPhone应用程序(不是Safari.app)中的webView查看网页,我想在网页上添加一行代码以引入一些自定义JS.

If the jQuery mobile webpage is viewed in a normal mobile browser, I want all to function normally. BUT if the webpage is viewed using the webView in the iPhone app (not Safari.app) I am designing, I want to include an additional line of code on the webpage to pull in some custom JS.

这就是我要添加到在iPhone应用程序的webView内部查看的页面仅在中显示的内容:

Here's what I want to be added to the page ONLY IF viewed inside of my iPhone app's webView:

<script type="text/javascript" src="http://www.example.com/mobile/js/custom-jqm-defaults.js"></script>

需要插入此代码(根据jQuery mobiledocs )之前加载jQuery Mobile.这可能吗?如果是这样,您能指出正确的方向并给我一些代码吗?

This code needs to be pulled in (according to the jQuery mobile docs) before jQuery Mobile is loaded. Is this possible? And if so, could you point me in the right direction and give me some code?

编辑

我发现了此链接,其中Facebook检测是否在应用程序中对其进行了查看.还有另一种方法可以明显不使用FB API吗?这是他们的代码:

I found this link whereby Facebook detects if they are being viewed WITHIN an app. Is there another way to do this obviously NOT using the FB API? Here is their code:

if (FB.UA.nativeApp()) {
  // Hide your credits stuff
}

推荐答案

您可以在NSURLRequest中更改用户代理,然后在服务器上检查该代理.

You can change the user agent in your NSURLRequest, and then check for that agent on your server.

在应用程序端更改它简单.

这篇关于iOS应用程序jQuery Mobile网站-仅在本机iPhone应用程序中查看过页面时,才包括JS文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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