【问题标题】:How to make an external link for apps (PhoneGap)如何为应用程序制作外部链接(PhoneGap)
【发布时间】:2019-01-14 16:41:00
【问题描述】:

由于我是编程初学者,所以我在制作我的第一个应用程序时遇到了麻烦。使用 PhoneGap,我压缩了我的 HTML 和 CSS 文件夹,并使用 PhoneGap Build 服务构建了它们。到达那里后,我按照步骤(使用 QR 码)在我的 Android 平板电脑上安装了我的应用程序。平板电脑是华硕设备。我测试了我的新应用程序,除外部链接外,一切正常。我相信这与应用程序在调用链接时未打开浏览器有关。任何帮助表示赞赏!

这是我的应用程序中的一个页面。它上面有最多的外部链接:

<?xml version="1.0" encoding="UTF-8" ?>

<widget xmlns		= "https://www.w3.org/ns/widgets"
		xmlns:gap   = "http://phonegap.com/ns/1.0"
		id          = "com.MylesCohenChan.Chair.it.y"
		versionCode = "1"
		version     = "1.0.0" >
		
	<name>Chair.it.y</name>
	
	<description> This is a charity organization involving furniture.</description>
	
	<author href = "spacerobot.ca" email = "mylescohenchan@gmail.com">
		Myles-Cohen Chan
	</author>
	
	
	<plugin name="cordova-plugin-inappbrowser" source="npm" />
	
	
</widget>
body {
	font-family: arial, sans-serif;

}

h1 {
	margin: 10px;
	padding: 10px 100px 10px 5px;
	line-height:10px;
	border-bottom: 1px solid rgb(217, 217, 217);
	font-size: 100%;
}

img {
	height: 40px;
	width: 170px;
}
	

h2 {
	color: black;
	text-align: center;
	font-size: 100%;
	
}




	

a {
	display: block;
	text-decoration: none;
	color: white;

}


h3 {
	padding: 10px;
	text-align: center;
	font-size: 120%;
}

div {
	border-radius: 25px;
	background: #E74C3C;
	width: 100px;
	text-align: center;
	padding: 10px;
	
}

h4 {
	padding: 10px;
	font-size: 100%;
	max-width: 500px;
	margin: auto;
}

p {
	border-radius: 25px;
	border: 2px solid grey;
	padding: 8px;
	background-color: white;
	max-width: 500px;
	margin: auto;
}

ul {
	padding: 0px;
	margin: 0px;
	max-width: 500px;
	margin: auto;
}

li {	

	border-radius: 25px;
	background: steelblue;
	text-align: center;
	padding: 10px;
	margin: 10px;
	list-style-type: none;
	background-image: url(images/chevron.png);
	background-repeat: no-repeat;
	background-position: right;
	color: white;
}

h5 {
	padding: 10px;
	font-size: 100%;
	max-width: 500px;
	margin: auto;
}

h6 {
	padding: 10px;
	font-size: 100%;
	max-width: 500px;
	margin: auto;
}

div:hover {
	background: #FF8800;
}

li:hover {
	background: #00A1FF;
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">


<html lang="en">
<head>
	<title>Donate</title>

	<meta http-equiv="Content-Type" content= "text/html; charset=utf-8">

	<meta name="viewport" content="width=device-width">
	<meta name="viewport" content="initial-scale=1.0">

	<link media="screen" href="Donate.css" type="text/css" rel="stylesheet">
	
<script language="javascript">
		var ua = navigator.userAgent;
		if (ua.indexOf("iPhone") > 0) {
			document.location.replace("card.html");
		}

		function switchPage(page){
			document.location.replace(page + ".html");
		
	</script>

</head>

<body background="images/Chair2.jpg">

<h1><img style="display: inline;" src="images/Chair-it-y symbol.png" alt="logo" /></h1>
<h2>Donate</h2>

<div><a onclick="switchPage('index');">Home</a></div>

<h3> Prefered Methods of Donation</h3>

<h4>1. Bring It</h4>

<p>

If you are interested in donating some furniture, one option is to bring it to our store*.<br><br>

Once you arive, we can then assist you in unloading your vehicle. When donating, no payment is required, 
but is suggested so that we can continue to fund Chair-it-y's different departments.<br><br><br>


<big>*</big><small><small>Our store does not actually exist, because this is not a real chairity. It is a made-up organization 
designed for this assignment's purposes.</small></small>

</p>

<ul>

<li><a href="https://www.google.ca/maps/place/Value+Village/@49.2279116,-123.0719501,15z/data=!4m5!3m4
!1s0x5486742462cc4d81:0x73bc6aed39b44a57!8m2!3d49.2263335!4d-123.0
659267">Store Location</a></li>

</ul>




<h5>2. Mail It</h5>

<p>

Do you live too far away, or don't have the means to transport your furniture? Well, that's not a problem! 
You can just mail it to us. <br><br>

Using the address givin to you above in the "Store Location" tab, all you have
 to do is package your item and ship it to us! It's that easy. <br><br><br>

<big>*</big><small><small>You don't actually have to package your item, our store does not exist.</small></small>

<ul>
<li><a href="https://www.canadapost.ca/tools/pg/manual/PGabcmail-e.asp" onclick="window.open(this.href,'_blank'); return false;" >Canada Post Shipping Info</a></li>
</ul>




<h6>3. Pick Up</h6>

<p>

Is shipping a problem for you? Well, it's a problem no more! <br><br>

Chair-it-y will gladly come right to your doorstep and pick up your furniture, as long as you live within the 
Greater Vancouver area and schedule the pickup to be between Monday and Friday. If you live outside Greater 
Vancouver, we can still try to make and effort by meeting somewhere halfway.

</p>

<ul>

<li onclick="switchPage('Email Form');">Schedule a Pickup</li>

</ul>

</body>
</html>

图片文件不包括在内,所以当你们打开它时应该没有标志和背景。如果您有任何问题,请在这里问他们。谢谢!

【问题讨论】:

  • 到底是什么问题?图片加载不出来?或者您想添加一个网站链接并在您的应用程序中打开它?因为第二个是不可能的。
  • 我想在我的应用程序中添加指向网站的链接,但它会在浏览器中启动该网站。那可能吗?如果有,怎么做?

标签: javascript android html css phonegap


【解决方案1】:

我在很长一段时间内都面临这个问题,这就是为什么我不得不就我所做的事情向您提供建议。 如果你想显示外部网站,你可以,但你需要像这样将 inappbrowser 插件添加到你的 config.xml 文件中:

然后在你的html页面上,使用这个例子:

加拿大邮政运输信息

完全按照上面写的方式尝试并检查,希望对您有所帮助。祝你好运

如果插件是通过命令添加的,它可能不起作用。这应该可以解决它,请按照下列步骤操作: 完全删除 inappbrowser。您可以转到插件文件夹并将其删除到垃圾箱,但是最好的删除方法是导航到终端中的项目文件夹(如果在 Mac 上)或 cmd(如果是 Windows)。键入以下命令以完全删除插件: 科尔多瓦插件删除inappbrowser 一旦您确认插件已被删除,您可以通过以下命令进行验证 科尔多瓦插件 -l 该命令应该列出您项目中的所有插件,如果您不再看到 inappbrowser,这意味着它已被删除,您现在需要做的就是转到 Config.xml 并通过像这样键入它来手动添加插件:

html代码应该和我之前给你的代码一样,然后正常重建你的项目。如果您使用浏览器测试,请通过扫描二维码 bcos 使用真实设备进行测试,链接将在新选项卡中打开,因此您可以使用真实设备或模拟器进行 2 次测试,希望对您有所帮助,让我知道。

【讨论】:

  • 谢谢!很有帮助!
  • 你能解决问题吗?让我知道,也许其他人可能有替代方案
  • 它似乎不起作用。我实现了你给我的代码,但链接仍然没有在浏览器中打开页面。您还有其他建议吗?
  • 好的,我想你可以解决它。从您的项目中完全删除 inappbrowser。您可以转到插件文件夹并将其删除到垃圾箱,但是删除插件的最佳方法是如果您在 Mac 上导航到终端中的项目文件夹,如果在 windows 上导航到 cmd。输入以下命令以完全删除插件:
  • 谢谢!你一直很有帮助,manlixo4u!非常感谢您帮助我!只是该应用程序仍然没有在浏览器中打开页面。我已经更新了我上面的代码,也许它可以帮助!
【解决方案2】:

1:安装这个cordova插件。

cordova plugin add cordova-plugin-inappbrowser

2:像这样添加链接。

<a href="#" onclick="window.open('https://www.google.com/', '_blank', 'location=yes');" >Google</a>

在 INAPPBROWSER 中打开使用'_blank'

在系统浏览器中打开使用'_system'

在这里查看更多details

【讨论】:

  • 如何安装插件?我刚刚安装了 Cordova 命令行并在命令提示符下安装了 npm。现在,我该怎么办?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多