如何重新加载页面而不破坏代码?

发布于 2024-12-01 02:25:48 字数 1249 浏览 1 评论 0原文

我在我的系统中集成了一个外部脚本,允许我的用户在观看视频后获得积分。单击链接后,将弹出一个窗口来加载视频。视频结束后有一个回调“callback_on_conversion”。我需要隐藏按钮,但这并不容易。阅读集成指南,我发现:

“这种异步行为有一个限制:JavaScript 代码 你可以在这些回调函数中运行,也可以不使用document.write 那样的功能是行不通的。相反,我们建议 在您的页面中创建/插入新元素(例如后备广告标签) 使用 DOM 和 jQuery。”

这实际上是脚本。同样,我不知道如何在视频结束时隐藏“a”链接。

       <script src="http://iframe.sponsorpay.com/javascripts/widget/v1/widgets.js" charset="utf-8"> </script>
        <script type="text/javascript">

        var sp_object = new SPONSORPAY.Video.Iframe({
            api_host: 'iframe.sponsorpay.com',
            asset_host: 'iframe.sponsorpay.com',
            appid: 'xxxx',
            uid: 'demouser',
            width: '750',
            height: '750',
            display_format: 'bare_player',
            callback_on_start: function() { alert('Video Ready'); },
            callback_on_conversion: function() { alert('finished'); },
            callback_no_offers: function() { alert('No video avabile.'); }
        });

        sp_object.backgroundLoad();
</script>

<a href="#" id="showvideo" name="showvideo" class="showvideo" onClick="sp_object.showVideo()">Load</a>

我应该做什么来防止代码破坏?谢谢!

i have integrated in my system an external script to allow my users to receive credits after watched a video. After they clicked a link, a popup will load the video. After the video finished there is a callback "callback_on_conversion". I need to hide the button but it's not really easy. Reading the integration guide, i found:

"This asynchronous behavior has a limitation: The javascript code that
you can run in these callback functions may not use the document.write
function as that will not work. Instead, we recommend that for
creating/inserting new elements (e.g. fallback AdTags) in the page you
use DOM and jQuery."

This is the actually script. Again, i don't know how to hide the "a" link when video finished.

       <script src="http://iframe.sponsorpay.com/javascripts/widget/v1/widgets.js" charset="utf-8"> </script>
        <script type="text/javascript">

        var sp_object = new SPONSORPAY.Video.Iframe({
            api_host: 'iframe.sponsorpay.com',
            asset_host: 'iframe.sponsorpay.com',
            appid: 'xxxx',
            uid: 'demouser',
            width: '750',
            height: '750',
            display_format: 'bare_player',
            callback_on_start: function() { alert('Video Ready'); },
            callback_on_conversion: function() { alert('finished'); },
            callback_no_offers: function() { alert('No video avabile.'); }
        });

        sp_object.backgroundLoad();
</script>

<a href="#" id="showvideo" name="showvideo" class="showvideo" onClick="sp_object.showVideo()">Load</a>

What should i do to prevent code breaking? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱的那么颓废 2024-12-08 02:25:48

jQuery 有很多操作 DOM 树的函数。例如,这会选择 ID = 'showvideo' 的属性并将其删除。

$('a#showvideo').remove();

请注意,如果有多个此类元素,则仅采用第一个,但您也可以使用类进行选择:

$('a.showvideo').remove();

jQuery has LOTS of functions to manipulate the DOM tree. For instance, this selects the attribute with ID = 'showvideo' and removes it.

$('a#showvideo').remove();

Note that if there's more than 1 such element, only the first will be taken, but you can also select using a class:

$('a.showvideo').remove();
捂风挽笑 2024-12-08 02:25:48

如果在视频结束时调用callback_on_conversion,您可以简单地使用 jquery 隐藏它。 http://api.jquery.com/hide/

callback_on_conversion: function() {
    $("a#showvideo").hide();
};

If callback_on_conversion is called when the video finishes you could simply hide it with jquery. http://api.jquery.com/hide/

callback_on_conversion: function() {
    $("a#showvideo").hide();
};
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文