こんにちは、twitch から埋め込みコード内のオブジェクトのデータとパラメーターの値を変更しようとしています。私はJavaScriptが得意ではないので、助けが必要です。実際、私のスクリプトは入力ボタンで動作しますが、twitch ビデオをリンクで更新したかったのです。
私のHTMLコード:
<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>
<a href="#" onclick="changestream1(riotgames);" id="streamName" value="Change Stream">riotgames</a>
私の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);
}
私がこれをどのように考えているかのビジュアルが必要な場合は、リンクを押してください:D JsFiddle
よろしく、Rac3Mul。