在HTML/javascript中的多个URL之间切换
下面是我想要的一个例子,但它目前有两个缺陷在HTML/javascript中的多个URL之间切换,javascript,html,url,Javascript,Html,Url,下面是我想要的一个例子,但它目前有两个缺陷 我相信这个顺序是不正确的,因为我看不到google.com以外的任何url站点。代码中某些项目的位置必须关闭。我在没有弹出窗口拦截器的情况下尝试过,但仍然无法显示其他窗口 我相信这个程序应该在不同的窗口/选项卡中打开。我想我的打开下一个网址在同一个窗口和标签,并取代原来的 msn取代谷歌;msn被雅虎取代 我很感激你的帮助。谢谢大家 代码: var urlist=['http://www.google.com', 'http://www.msn.
- msn取代谷歌;msn被雅虎取代
var urlist=['http://www.google.com', 'http://www.msn.com', 'http://www.yahoo.com'];
var-wnd;
var curIndex=0;//保存当前url的当前索引的变量
函数openWindow(){
wnd=window.open(urlist[curIndex],'','');
setTimeout(函数(){
wnd.close();//关闭当前窗口
curIndex++;//增加索引
if(curIndex
如果在同一页面中打开,javascript将消失。这行不通。一旦google.com被打开,这将是你的javascript的结束。所以你应该打开一个新的标签或者考虑使用IFRAMS。< /P>
有关更多信息,请参见此处:
您可以重新使用Windows实例:
<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
var urlList = ['http://www.google.com', 'http://www.msn.com', 'http://www.yahoo.com'];
var wnd;
var curIndex = 0; // a var to hold the current index of the current url
function openWindow(){
wnd = wnd || window.open();
wnd.location.href = urlList[curIndex];
setTimeout(function () {
curIndex++; //increment the index
// If all urls have been showed, close our window instance
if(curIndex < urlList.length) openWindow(); else wnd.close();
}, 2000);
}
openWindow();
</script>
</html>
var urlist=['http://www.google.com', 'http://www.msn.com', 'http://www.yahoo.com'];
var-wnd;
var curIndex=0;//保存当前url的当前索引的变量
函数openWindow(){
wnd=wnd | | window.open();
wnd.location.href=urlist[curIndex];
setTimeout(函数(){
curIndex++;//增加索引
//如果已显示所有URL,请关闭窗口实例
if(curIndex
FYI。对于html5 doctype,您的doctype应该是
。这不是真的,您仍然可以更改窗口的位置。但是您不能与窗口的内容进行通信。您如何才能做到这一点?当你打开一个新页面时,javascript就消失了。请告诉我var my\u window=window.open('https://google.com'); /*....*/ my_window.location.href='class1https://example.com“
当google.com打开时。你还有你的javascript吗?。你的更新将如何工作。你仍然可以重置位置对象,这就是我所知道的。请提供你的解决方案。感谢您选择code->[ctrl]+[c]
->[ctrl]+[alt]+[j]
(打开您的控制台)->[ctrl]+[v]
->[enter]
->查看魔法展开。我猜他会想把它写在js文件中,不在console@Fyre它将产生相同的结果,因为在控制台中运行的代码将以与当前页面中嵌入的运行代码相同的权限运行。我想我误解了这个问题。他说它应该在同一个选项卡中打开,而在您的解决方案中,它应该在新选项卡中打开。
<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
var urlList = ['http://www.google.com', 'http://www.msn.com', 'http://www.yahoo.com'];
var wnd;
var curIndex = 0; // a var to hold the current index of the current url
function openWindow(){
wnd = wnd || window.open();
wnd.location.href = urlList[curIndex];
setTimeout(function () {
curIndex++; //increment the index
// If all urls have been showed, close our window instance
if(curIndex < urlList.length) openWindow(); else wnd.close();
}, 2000);
}
openWindow();
</script>
</html>