2014-02-20 30 views
0

所以我做了下面,看起來像它正在執行url1罰款,但url2仍然沒有被應用。單獨他們工作得很好,只是沒有togeather。如何在同一個函數中傳遞多個「var url」?

<script type="text/javascript"> 
<!-- 
function Start() { 
var url1 = "http://stream.xxx.net:7300/event/start"; 
var url2 = "http://stream.xxx.net:7301/event/start"; 
window.frames["ifrmInitLiveBroadcast"].location = url1; 
window.frames["ifrmInitLiveBroadcast"].location = url2; 
alert("Live Broadcast Started") 
} 
function Stop() { 
var url1 = "http://stream.xxx.net:7300/event/stop"; 
var url2 = "http://stream.xxx.net:7301/event/stop"; 
window.frames["ifrmInitLiveBroadcast"].location = url1; 
window.frames["ifrmInitLiveBroadcast"].location = url2; 
alert("Live Broadcast Terminated") 
} 
//--> 
</script> 

下面是在同一腳本中關聯的表代碼,也許這裏需要更改一些內容嗎?

<table style="width: 400" cellspacing="1" class="style7"> 
<tr> 
<td style="height: 50px; width: 200px; text-align: center"> 
<button onclick="Start()" style="height: 30">Start It</button>                          <br> 
<iframe name="ifrmInitLiveBroadcast" id="ifrmInitLiveBroadcast" src="" width="0" height="0" scrolling="0" frameborder="0" ></iframe> 
</td> 
<td style="height: 50px; text-align: center; width: 200px"> 
<button type="button" onclick="Stop()" style="height: 30px">Stop It</button><br> 
<iframe name="ifrmInitLiveBroadcast" id="ifrmInitLiveBroadcast" src="" width="0" height="0" scrolling="0" frameborder="0" ></iframe> 
</td> 
</tr> 
</table> 
+2

您的框架看起來都具有相同的名稱。 – cmbuckley

回答

0

,你喜歡,你可以創建許多唯一命名的變量,例如:

var url1 = 'http:/site1.com' 
var url2 = 'http://site2.com' 
var url3 = 'http://site3.com' 

alert('Visit one of these sites: ' + url1 + ' ' + url2 + ' ' + url3); 
0

是的,但要確保你有window.frames名爲myUniqueFrameIdentifier另一幀/ IFRAME:

function Start() { 
    var url1 = "http://xxx.yyy.com:7000/event/start"; 
    var url2 = "http://xxx.yyy.com:7000/event/startAgain"; 
    window.frames["ifrmInitLiveBroadcast"].location = url1; 
    window.frames["myUniqueFrameIdentifier"].location = url2; 
    alert("Event Started") 
} 
function Stop() { 
    var url1 = "http://xxx.yyy.com:7002/event/stop"; 
    var url2 = "http://xxx.yyy.com:7000/event/stopAgain"; 
    window.frames["ifrmInitLiveBroadcast"].location = url1; 
    window.frames["myUniqueFrameIdentifier"].location = url2; 
    alert("Event Terminated") 
} 

另外,在您的代碼中,您需要重命名其中一個iframe,id和/或名稱需要是唯一的:

<table style="width: 400" cellspacing="1" class="style7"> 
    <tr> 
     <td style="height: 50px; width: 200px; text-align: center"> 
     <button onclick="Start()" style="height: 30">Start It</button>                          <br> 
     <iframe name="ifrmInitLiveBroadcast" id="ifrmInitLiveBroadcast" src="" width="0" height="0" scrolling="0" frameborder="0" ></iframe> 
     </td> 
     <td style="height: 50px; text-align: center; width: 200px"> 
     <button type="button" onclick="Stop()" style="height: 30px">Stop It</button><br> 
     <iframe name="myUniqueFrameIdentifier" id="myUniqueFrameIdentifier" src="" width="0" height="0" scrolling="0" frameborder="0" ></iframe> 
     </td> 
    </tr> 
</table> 
+0

我試過了,但還是有東西丟失?我編輯了原始問題。謝謝! – user3334034

+0

@ user3334034您的iframe具有相同的名稱。往上看 –

相關問題