使用javascript实现Pinterest时出错

时间:2013-03-14 13:29:34

标签: javascript android cordova pinterest

我正在我的phonegap android应用程序中实现Pinterest。我使用的代码如下:

<html>
<head>
    <title>PINTEREST</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
   <meta name="layout" content="mobile"/>
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
</head>
<body>
<a data-pin-config="above" href="https://pinterest.com/pin/create/button/?url=http%3A%2F%2Fwww.flickr.com%2Fphotos%2Fkentbrew%2F6851755809%2F&media=http%3A%2F%2Ffarm8.staticflickr.com%2F7027%2F6851755809_df5b2051c9_z.jpg&description=Next%20stop%3A%20Pinterest" data-pin-do="buttonPin" ><img src="https://assets.pinterest.com/images/pidgets/pin_it_button.png" /></a>
<script type="text/javascript" src="https://assets.pinterest.com/js/pinit.js"></script>
</body>
</html>

它在浏览器中工作正常,但当我在Android设备上安装它时,我收到警报:

  

发生网络错误(文件://assests.pinterest.com/pidget.html)#from = file%3A%2F%2F%2Fandroid_asset%2Ftest.html&amp; type = pidget)

这是因为

<script type="text/javascript" src="https://assets.pinterest.com/js/pinit.js"></script> 

但我必须使用它。请帮我解决问题。

4 个答案:

答案 0 :(得分:0)

您可以将资产下载到本地。否则,如果没有网络连接,它将不会显示在手机上。使用其他网站的资源可能也是一个坏主意,请参阅"Inline Linking (Hot Links)"

答案 1 :(得分:0)

您的应用程序可能没有INTERNET permission。检查它是否包含在AndroidManifest.xml

答案 2 :(得分:0)

我通过异步加载pinit.js解决了这个问题。我用的是:

 <script type="text/javascript">
(function (w, d, load) {
 var script,
 first = d.getElementsByTagName('SCRIPT')[0],  
 n = load.length,
 i = 0,
 go = function () {
   for (i = 0; i < n; i = i + 1) {
     script = d.createElement('SCRIPT');
     script.type = 'text/javascript';
     script.async = true;
     script.src = load[i];
     first.parentNode.insertBefore(script, first);
   }
 }
 if (w.attachEvent) {
   w.attachEvent('onload', go);
 } else {
   w.addEventListener('load', go, false);
 }
}(window, document,
 ['//assets.pinterest.com/js/pinit.js']
));    
</script>

答案 3 :(得分:0)

您可以使用SocialSharing phonegap插件在Android上固定内容。只需添加this plugin并添加一个按钮:

&LT; button onclick =“window.plugins.socialsharing.shareVia('pinterest','哇!')”&gt; Pin it!&lt; /按钮&GT;

不可能更容易:)