问题描述
||
我使用phonegap创建了一个基本项目。并将这部分HTML代码添加到我的index.hmtl中
单击youtube链接将在Phonegap中启动Youtube移动网站(一旦启动,就无法返回我的phonegap视图)
如何启用HREF链接以在iPhone / iPad上打开本机youtube应用程序?
href链接符合Apple关于Youtube链接的规范,如下所示:
https://developer.apple.com/library/safari/#featuredarticles/iPhoneURLScheme_Reference/Articles/YouTubeLinks.html
我的Index.html:
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/
TR/html4/strict.dtd\">
<html>
<head>
<!-- Change this if you want to allow scaling -->
<Meta name=\"viewport\" content=\"width=default-width; user-
scalable=no\" />
<Meta http-equiv=\"Content-type\" content=\"text/html;
charset=utf-8\">
<title>MyTube</title>
<!-- iPad/iPhone specific css below,add after your main css >
<link rel=\"stylesheet\" media=\"only screen and (max-device-width:
1024px)\" href=\"ipad.css\" type=\"text/css\" />
<link rel=\"stylesheet\" media=\"only screen and (max-device-width:
480px)\" href=\"iphone.css\" type=\"text/css\" />
-->
<!-- If you application is targeting iOS BEFORE 4.0 you MUST put
json2.js from http://www.JSON.org/json2.js into your www directory and
include it here -->
<script type=\"text/javascript\" charset=\"utf-8\" src=\"phonegap.
0.9.4.min.js\"></script>
<script type=\"text/javascript\" charset=\"utf-8\">
// If you want to prevent dragging,uncomment this section
/*
function preventBehavior(e)
{
e.preventDefault();
};
document.addEventListener(\"touchmove\",preventBehavior,false);
*/
function onBodyLoad()
{
document.addEventListener(\"deviceready\",onDeviceReady,false);
}
/* When this function is called,PhoneGap has been initialized and is
ready to roll */
function onDeviceReady()
{
// do your thing!
}
</script>
</head>
<body onload=\"onBodyLoad()\">
<h1> My You tube Links </h1>
<a href=\"http://www.youtube.com/v/NkTrG-gpIzE\"> SOURCE-CODE
Trailer </a>
</body>
</html>
解决方法
我尝试过并得到相同的结果。这很奇怪,因为我还假设到YouTube的链接会触发本机YouTube应用。我发现的一件事是,嵌入将执行您要执行的操作,但没有其他任何方式。
<object width=\"300\" height=\"199\">
<param name=\"movie\" value=\"http://www.youtube.com/v/NkTrG-gpIzE?fs=1&hl=en_US&rel=0\"></param>
<param name=\"allowFullScreen\" value=\"true\"></param>
<param name=\"allowscriptaccess\" value=\"always\"></param>
<embed src=\"http://www.youtube.com/v/NkTrG-gpIzE?fs=1&hl=en_US&rel=0\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"300\" height=\"199\"></embed>
</object>
我唯一的建议是让您在PhoneGap Google网上论坛发帖,但我发现您几分钟前就完成了。如果我发现其他任何东西,我将尝试分享,但是到目前为止,嵌入方法一直是唯一可行的方法。