简体   繁体   English

minicart js-添加到购物车在新选项卡上打开

[英]minicart js - add to cart opening on new tab

I am trying to add minicart js to the website I am building but I appear to be having some issue. 我正在尝试将minicart js添加到我正在构建的网站中,但似乎出现了一些问题。

With reference to this question, the accepted answer links a demo which opens a mini cart GUI when the add to cart button is pressed. 关于问题,接受的答案链接了一个演示,该演示在按下添加到购物车按钮时打开迷你购物车GUI。

However, when I inspect element and copy the exact code used in the demo into my editor and run the page, when I press add to cart, paypal opens on another page, rather than displaying the mini cart. 但是,当我检查元素并将演示中使用的确切代码复制到编辑器中并运行该页面时,当我按添加到购物车时,贝宝会在另一页上打开,而不是显示迷你购物车。

I have been trying different versions to see if it mattered (3.0.6 is the latest) but having the same issue. 我一直在尝试不同的版本,以查看它是否重要(3.0.6是最新版本),但存在相同的问题。

I would just like the mini cart to display on my page. 我只希望迷你购物车显示在我的页面上。

EDIT 编辑

I've found another post which said to remove the code protection which apparently worked for another user but unfortunately did not work for me, I'm at a loss as to why the minicart window won't display. 我找到了另一条帖子,说它删除了显然对另一个用户有效的代码保护,但不幸的是对我不起作用,我对为什么迷你购物车窗口无法显示感到困惑。

This is the code I am using which works for the demo but not for my page: 这是我正在使用的代码,适用于演示但不适用于我的页面:

<html>
<body>

<form target="paypal" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" >
    <input type="hidden" name="cmd" value="_cart">
    <input type="hidden" name="business" value="demo@gmail.com">
    <input type="hidden" name="lc" value="US">
    <input type="hidden" name="item_name" value="test Add to Cart">
    <input type="hidden" name="amount" value="12.00">
    <input type="hidden" name="currency_code" value="USD">
    <input type="hidden" name="return" value="https://www.paypaltech.com/vimal/test.php">
    <input type="hidden" name="add" value="1">
    <input type="hidden" name="bn" value="PP-ShopCartBF:btn_cart_LG.gif:NonHosted">
    <input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_cart_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
    <img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

<script src="//cdnjs.cloudflare.com/ajax/libs/minicart/3.0.3/minicart.min.js"></script>
<script>
    paypal.minicart.render();
</script>

</body>
</html>

I finally got it working, instead of using the link provided in the documentation, I downloaded the source code instead and included the link to the minicart.js file which i put into my project structure. 我终于使它工作了,而不是使用文档中提供的链接,而是下载了源代码,并包含了指向minicart.js文件的链接,该文件已放入我的项目结构中。

Everything worked after that :) 之后一切正常:)

Final code: 最终代码:

<html>
<body>

    <form target="paypal" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
        <input type="hidden" name="cmd" value="_cart">
        <input type="hidden" name="business" value="demo@gmail.com">
        <input type="hidden" name="lc" value="US">
        <input type="hidden" name="item_name" value="test Add to Cart">
        <input type="hidden" name="amount" value="12.00">
        <input type="hidden" name="currency_code" value="EUR">
        <input type="hidden" name="return" value="https://www.paypaltech.com/vimal/test.php">
        <input type="hidden" name="add" value="1">
        <input type="hidden" name="bn" value="PP-ShopCartBF:btn_cart_LG.gif:NonHosted">
        <input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_cart_LG.gif" name="submit" alt="PayPal - The safer, easier way to pay online!">
        <img alt="" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
    </form>

    <script src="minicart.js"></script>
    <script>
        paypal.minicart.render();   
    </script>
</body>
</html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM