如何重新加载页面而不破坏代码?
我在我的系统中集成了一个外部脚本,允许我的用户在观看视频后获得积分。单击链接后,将弹出一个窗口来加载视频。视频结束后有一个回调“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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
jQuery 有很多操作 DOM 树的函数。例如,这会选择 ID = 'showvideo' 的属性并将其删除。
请注意,如果有多个此类元素,则仅采用第一个,但您也可以使用类进行选择:
jQuery has LOTS of functions to manipulate the DOM tree. For instance, this selects the attribute with ID = 'showvideo' and removes it.
Note that if there's more than 1 such element, only the first will be taken, but you can also select using a class:
如果在视频结束时调用
callback_on_conversion
,您可以简单地使用 jquery 隐藏它。 http://api.jquery.com/hide/If
callback_on_conversion
is called when the video finishes you could simply hide it with jquery. http://api.jquery.com/hide/