在iframe中打开变量链接 [英] Open link from variable in iframe
本文介绍了在iframe中打开变量链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<script language="Javascript" type="text/javascript">
function Next(){
var randp = Math.floor(Math.random()*3);
switch(randp){
case 0:
var websel = "http://w3schools.com";
break;
case 1:
var websel = "http://www.bbc.com/";
break;
case 2:
var websel = "http://en.wikipedia.org/wiki/BBC";
break;
default:
document.write("Error SWITCH(randp) " + randp + " ");
break;
}
}
</script>
<iframe name="iframea" src="http://w3schools.com" seamless="seamless" scrolling="auto" height="560px" width="1080px" align="middle" scale="1.5"></iframe>
<input type="button" value="Next" onClick="Next()">
对不起,基本问题。我需要添加什么来让下一个按钮打开一个链接(该链接是来自函数的变量),并将目标作为iframe。
谢谢
Sorry for the basic question. What would I need to add to have the next button open a link (the link being a variable from a function) with the target as the iframe. Thanks
推荐答案
您必须更改iframe的src,如下所示:
You have to change the src of your iframe as following:
<script language="Javascript" type="text/javascript">
function Next(){
var randp = Math.floor(Math.random()*3);
switch(randp){
case 0:
var websel = "http://w3schools.com";
break;
case 1:
var websel = "http://www.bbc.com/";
break;
case 2:
var websel = "http://en.wikipedia.org/wiki/BBC";
break;
default:
document.write("Error SWITCH(randp) " + randp + " ");
break;
}
alert(websel);
document.getElementById("iframea").src=websel;
}
</script>
<iframe name="iframea" id="iframea" src="http://w3schools.com" seamless="seamless" scrolling="auto" height="560px" width="1080px" align="middle" scale="1.5"></iframe>
<input type="button" value="Next" onClick="Next()">
顺便说一下,您可以在此网站上查找这个问题是类似的。
By the way, you might look on this website this question is similar.
这篇关于在iframe中打开变量链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文