Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在embed from twitch中更改对象的数据和参数值_Javascript_Html_Object - Fatal编程技术网

Javascript 在embed from twitch中更改对象的数据和参数值

Javascript 在embed from twitch中更改对象的数据和参数值,javascript,html,object,Javascript,Html,Object,您好,我正在尝试从twitch更改嵌入代码中的对象数据和参数值。 我不太擅长javascript,需要一些帮助。 我做研究很不走运。 感谢所有帮助:) 我想要更改的嵌入代码(这是一个新的嵌入代码,没有编辑) 其思想是js将在对象中创建数据,并在参数中创建值。 如果你想知道我是怎么想的,请点击链接:D 链接到将使用此功能的网站 您在+“&auto\u play=true&start\u volume=25”中缺少+符号 你应该检查所有的代码,还有其他的错误,比如在调用cameCase时用小

您好,我正在尝试从twitch更改嵌入代码中的对象数据和参数值。
我不太擅长javascript,需要一些帮助。
我做研究很不走运。
感谢所有帮助:)
我想要更改的嵌入代码(这是一个新的嵌入代码,没有编辑)

其思想是js将在对象中创建数据,并在参数中创建值。
如果你想知道我是怎么想的,请点击链接:D


链接到将使用此功能的网站

您在+“&auto\u play=true&start\u volume=25”中缺少+符号

你应该检查所有的代码,还有其他的错误,比如在调用cameCase时用小写命名函数,检查每个变量,安装firebug并查看控制台中的日志

这应该行得通

<script type="text/javascript">
    function changestream1() {
        var streamInput = document.getElementById('streamName').value;
        var streamIn = ''; //This variable is not defined yet used on the last line of this block;
        var object = document.getElementById('live_embed_player_flash');
        var param = document.getElementById('param');
        object.setAttribute("data", "http://www.twitch.tv/widgets/live_embed_player.swf?channel=" + streamInput);
        param.setAttribute("value", "hostname=www.twitch.tv&channel=" + streamInput + "&auto_play=true&start_volume=25" + streamIn);
}
</script>
<div id="streamHolder">
    <object type="application/x-shockwave-flash" height="378" width="620" id="live_embed_player_flash" bgcolor="#000000">
        <param name="allowFullScreen" value="true" />
        <param name="allowScriptAccess" value="always" />
        <param name="allowNetworking" value="all" />
        <param name="movie" value="http://www.twitch.tv/widgets/live_embed_player.swf" />
        <param id="param" name="flashvars" />
    </object>
</div>
<div id="buttons">
    <input type="text" id="streamName" placeholder="Enter Streamer Name Here" style="width:12em;">
    <input type="button" id="button1" onclick="changestream1();" value="Change Stream">
</div>
<p>The name you enter will get put where the "streamInput" variable is in the javascript
<br>that is the general idea atleast</p>

函数changestream1(){
var streamInput=document.getElementById('streamName')。值;
var streamIn='';//此块的最后一行尚未定义此变量;
var object=document.getElementById('live_embed_player_flash');
var param=document.getElementById('param');
setAttribute(“数据”http://www.twitch.tv/widgets/live_embed_player.swf?channel=“+输入);
param.setAttribute(“value”、“hostname=www.twitch.tv&channel=“+streamInput+”&auto_play=true&start_volume=25”+streamIn);
}
您输入的名称将放在javascript中“streamInput”变量所在的位置

这至少是总的想法


我从一个家伙那里得到了一个提示,他说:您可能需要在JavaScript中重新构建整个嵌入,然后在需要的地方追加或预加。因为我是js的初学者,所以我不知道该怎么做:PThis不能解决这个问题,但我会避免使用name对象作为变量名,因为它在某些编程语言中是一个保留变量。只是一个提示。谢谢你的提示。你救了我一个坏习惯:Pstill不起作用。而streamIn是一个错误。所以它应该是这样的:+streamInput+“&auto_play=true&start_volume=25”);这是一个旧变量。嗯,它确实在添加用户名,但是如何更新它以使其自动开始播放?尝试删除整个对象,然后再次附加它以模拟刷新(removeChild,appendChild),flash对象在页面加载时读取值,另一个解决方案是将对象放在内联框架内并重新加载框架,当然这需要使用一些服务器端(如php)和查询字符串来使用新值构建对象。。。将以下行添加到函数:object.parenNode.removeChild(object);document.getElementById('streamHolder').appendChild(对象);我明天带着密码四处看看。谢谢你到目前为止的帮助。你让我比我一个月内独自一人走得更远。:)
function changestream1(){
    var streamIn = document.getElementById('stream1').value;
    var objData= document.getElementById('live_embed_player_flash');
    var param = document.getElementById('param');

    objData.setAttribute("data", "http://www.twitch.tv/widgets/live_embed_player.swf?channel=" + streamIn); 
    param.setAttribute("value", "hostname=www.twitch.tv&channel=" + streamIn + "&auto_play=true&start_volume=25"); 
}
<script type="text/javascript">
    function changestream1() {
        var streamInput = document.getElementById('streamName').value;
        var streamIn = ''; //This variable is not defined yet used on the last line of this block;
        var object = document.getElementById('live_embed_player_flash');
        var param = document.getElementById('param');
        object.setAttribute("data", "http://www.twitch.tv/widgets/live_embed_player.swf?channel=" + streamInput);
        param.setAttribute("value", "hostname=www.twitch.tv&channel=" + streamInput + "&auto_play=true&start_volume=25" + streamIn);
}
</script>
<div id="streamHolder">
    <object type="application/x-shockwave-flash" height="378" width="620" id="live_embed_player_flash" bgcolor="#000000">
        <param name="allowFullScreen" value="true" />
        <param name="allowScriptAccess" value="always" />
        <param name="allowNetworking" value="all" />
        <param name="movie" value="http://www.twitch.tv/widgets/live_embed_player.swf" />
        <param id="param" name="flashvars" />
    </object>
</div>
<div id="buttons">
    <input type="text" id="streamName" placeholder="Enter Streamer Name Here" style="width:12em;">
    <input type="button" id="button1" onclick="changestream1();" value="Change Stream">
</div>
<p>The name you enter will get put where the "streamInput" variable is in the javascript
<br>that is the general idea atleast</p>