首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在不刷新页面的情况下使用新的字符串参数触发javascript

在不刷新页面的情况下使用新的字符串参数触发javascript
EN

Stack Overflow用户
提问于 2014-04-29 22:38:22
回答 1查看 204关注 0票数 0

我不知道如何正确地表达这个标题来解释我需要帮助的地方,所以这是我的故事。

下面的代码编写了一个包含视频的iframe:

代码语言:javascript
复制
<script type="text/javascript" src="http://sv.liveclicker.net/service/getEmbed?client_id=1915&amp;widget_id=1372752183&amp;player_custom_id=2264&amp;height=450&amp;width=800&amp;autoplay=false"></script>

我不能直接更改上面的脚本,所以我如何删除该脚本(以及生成的iframe),然后使用修改后的参数(高度和宽度)再次调用该脚本,以便用我的新尺寸写出新的iframe/视频-而且不需要刷新页面(好吧,刷新只会取消任何更改并再次恢复到旧脚本)。

顺便说一句,client_id、widget_id和player_custom_id需要与页面上的原始内容保持一致。

如果这可以用jQuery实现,那就太棒了(刚刚开始学习)。

感谢大家的帮助。

附加信息:在chrome中,当我单击脚本src时,它会显示以下内容:

代码语言:javascript
复制
if (!window.liveclicker) window.liveclicker = {};
if (!window.liveclicker || !liveclicker.receiveMessage) {
    var lcs = document.createElement('script');
    lcs.src = "http://sv.liveclicker.net/service/scripts/html5_js_c.js";
    lcs.type = "text/javascript";
    document.getElementsByTagName('head')[0].appendChild(lcs);
}

document.write('<iframe id="video_1372752183" name="video_1372752183" src="" width="800" height="450" frameBorder="0" scrolling="no" style="border:0;" webkitAllowFullScreen mozAllowFullScreen allowFullScreen></iframe>');
liveclicker.post_to_name = function (path, params, name) {
    var form = document.createElement("form");
    form.setAttribute("method", "post");
    form.setAttribute("action", path);
    form.setAttribute("target", name);
    for (var key in params) {
        if (params.hasOwnProperty(key)) {
            var hiddenField = document.createElement("input");
            hiddenField.setAttribute("type", "hidden");
            hiddenField.setAttribute("name", key);
            hiddenField.setAttribute("value", params[key]);
            form.appendChild(hiddenField);
        }
    }
    document.body.appendChild(form);
    form.submit();
};
liveclicker.post_to_name("//player.liveclicker.com/video-player/index.php\?widget_id=1372752183&accountid=1915&urlaccount=http://www.dhccare.com&accountCDN=http://ecdn.liveclicker.net/0079A8/cdn/&setrefererURL=http%3A%2F%2Fdhcstaging.liveclicker.com%2F&navfile=TODO&iframeDiv=video_1372752183&channel=0&player_custom_id=2264", {
    'shopapp_gview_buynow_avail': 0,
    'knobsEnabled': 'false',
    'shopapp_dview_buynow_avail': 0,
    'shareAvailable': 'false',
    'pseudo_streaming': 'true',
    'snapshotFeaturev2': 0,
    'buyAvailable': 'false',
    'navBuyNow': 'false',
    'aspectRatio': '16:9',
    'autostart': 'false',
    'ratingAvailablev2': 'false',
    'mosaic_skin': 'true',
    'sizing': 'crop',
    'channel': 2
}, "video_1372752183");

再次感谢!

EN

回答 1

Stack Overflow用户

发布于 2014-04-29 23:15:55

是否可以将脚本标记包装在一个div (id = "myDiv")中,然后使用innerHTML加载新视频/删除之前的视频,如下所示?

代码语言:javascript
复制
//Video1
<div id="myDiv">
<script type="text/javascript" src="http://sv.liveclicker.net/service/getEmbed?
client_id=1915&amp;widget_id=1372752183&amp;player_custom_id=2264&amp;height=450&amp;width=800&amp;autoplay=false"></script>
</div>

然后调用函数onclick按钮或图标来加载新视频:

代码语言:javascript
复制
//New script here...not sure what your script would be so I just put previous one..you can add height and width as parameters onclick...num1 and num2 would be what you need them to be

<button type="button" onclick="changeVideo(num1, num2)">Click</button>

function changeVideo(height, width) {
    document.getElementById("myDiv").innerHTML = '<script type="text/javascript"     
src="http://sv.liveclicker.net/service/getEmbed?client_id=&amp;widget_id=1372752183&amp;player_custom_id=2264&amp;height=' + height + '&amp;width=' + width + '&amp;autoplay=false"></script>';
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23367821

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档