【问题标题】:I want to open an external link inside my jquery mobile app (phongap build) but all external links open in browser我想在我的 jquery 移动应用程序(phongap 构建)中打开一个外部链接,但所有外部链接都在浏览器中打开
【发布时间】:2015-10-11 02:03:41
【问题描述】:

这是我第一次使用 phonegap 构建,我无法在我的应用程序中打开外部链接。我正在使用 jquery mobile 和 phonegap build 来发布一个 android 应用程序。在更新到 cli-5.2.0 之前,我可以使用以下代码打开应用程序内的外部链接

window.open('http://www.google.com','_self',false);

但是,在 cli-5.2.0 更新后,任何外部链接现在只能在 Chrome 或应用内浏览器中打开。有没有办法在应用内打开外部链接?

这是我的 config.xml 文件以防万一

<?xml version='1.0' encoding='utf-8'?>
    <widget id="com.test.chat" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0" xmlns:gap="http://phonegap.com/ns/1.0">

<name>Test 3.0</name>

<description>Test App</description>

<author email="dev@cordova.apache.org" href="http://cordova.io">Author
</author>
  <platform name="android">
    <allow-intent href="market:*" />
</platform>
<preference name="phonegap-version" value="cli-5.2.0" />
<content src="index.html" />
<gap:plugin name="cordova-plugin-whitelist" source="npm" />
<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />

<preference name="permissions" value="none"/>
<preference name="orientation" value="portrait"/>
<preference name="target-device" value="universal"/>
<gap:plugin name="org.apache.cordova.splashscreen" source="npm"/>
<!--<gap:plugin name="org.apache.cordova.inappbrowser" source="npm"/>-->

<feature name="http://api.phonegap.com/1.0/geolocation"/>
<preference name="SplashScreen" value="screen" />
<preference name="SplashScreenDelay" value="5000" />  
<preference name="fullscreen" value="true" />-->
<gap:splash gap:platform="android" gap:qualifier="port-ldpi"  src="res/drawable-port-ldpi/screen.png" />
<gap:splash gap:platform="android" gap:qualifier="port-mdpi"  src="res/drawable-port-mdpi/screen.png" />
<gap:splash gap:platform="android" gap:qualifier="port-hdpi"  src="res/drawable-port-hdpi/screen.png" />
<gap:splash gap:platform="android" gap:qualifier="port-xhdpi" src="res/drawable-port-xhdpi/screen.png" />
<gap:splash gap:platform="android" gap:qualifier="port-xxhdpi" src="res/drawable-port-xxhdpi/screen.png" />
<gap:splash gap:platform="android" gap:qualifier="port-xxxhdpi" src="res/drawable-port-xxxhdpi/screen.png" />
<gap:splash src="splash.png"/>

<icon src="icon.png" />

<icon src="res/drawable-port-ldpi/ldpi.png" gap:platform="android" gap:qualifier="ldpi" />
<icon src="res/drawable-port-mdpi/mdpi.png" gap:platform="android" gap:qualifier="mdpi" />
<icon src="res/drawable-port-hdpi/hdpi.png" gap:platform="android" gap:qualifier="hdpi" />
<icon src="res/drawable-port-xhdpi/xhdpi.png" gap:platform="android" gap:qualifier="xhdpi" />
<icon src="res/drawable-port-xxhdpi/xxhdpi.png" gap:platform="android" gap:qualifier="xxhdpi" />
<icon src="res/drawable-port-xxxhdpi/xxxhdpi.png" gap:platform="android" gap:qualifier="fr-xxhdpi" />
</widget> 

【问题讨论】:

    标签: android jquery-mobile phonegap-build


    【解决方案1】:

    您已将 inappbrowser 插件注释掉。只需取消注释以下行

    <gap:plugin name="org.apache.cordova.inappbrowser" source="npm"/>
    

    或尝试在 config.xml 中进行以下操作:

    <gap:plugin name="org.apache.cordova.inappbrowser" version="0.5.2" />
    

    这应该可行。

    【讨论】:

    • 确保在启动链接的网页上使用 CSP(内容安全策略)。文档位于 white-list plugin 的底部
    • @krunal 感谢您的回复。不幸的是,这不是我要找的。我不希望链接在应用内浏览器或手机浏览器(在本例中为 chrome)中打开。我希望页面在应用程序本身内打开
    • 好的。下面的链接可能会有所帮助。 link1link2
    猜你喜欢
    • 1970-01-01
    • 2011-06-14
    • 1970-01-01
    • 1970-01-01
    • 2021-11-11
    • 2014-07-12
    • 2018-02-11
    • 2017-08-06
    • 1970-01-01
    相关资源
    最近更新 更多