Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/405.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/85.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 如何修改此脚本以使Page2从iframe中加载?_Javascript_Html_Iframe - Fatal编程技术网

Javascript 如何修改此脚本以使Page2从iframe中加载?

Javascript 如何修改此脚本以使Page2从iframe中加载?,javascript,html,iframe,Javascript,Html,Iframe,这是我的代码,我正在寻找一个解决方案,在超时时,将第2页从iFrame中打开。非常感谢任何帮助或想法。Thx <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>MyFile</title> <script type="text/javascript">

这是我的代码,我正在寻找一个解决方案,在超时时,将第2页从iFrame中打开。非常感谢任何帮助或想法。Thx

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>MyFile</title>
    <script type="text/javascript">
    var frames = Array('http://www.mydomain.com/files/Page1', 55,
    'http://www.mydomain.com/files/Page2');
    var i = 0, len = frames.length;
    function ChangeSrc()
    {
    document.getElementById('frame').src = frames[i++];
    if (i >= len) return; // no more changing
    setTimeout('ChangeSrc()', (frames[i++]*1000));
    }
    window.onload = ChangeSrc;
    </script>
    </head>
    <body>
    <iframe src="" name="frame" id="frame" width="100%"height="100%></iframe>
    </body>
    </html>

我的文件
变量帧=数组('http://www.mydomain.com/files/Page1', 55,
'http://www.mydomain.com/files/Page2');
var i=0,len=frames.length;
函数ChangeSrc()
{
document.getElementById('frame').src=frames[i++];
if(i>=len)return;//不再更改
setTimeout('ChangeSrc()',(frames[i++]*1000));
}
window.onload=ChangeSrc;

您的代码有几点古怪:)

  • 让URL和超时值交织在一个简单的数组中“气味”。我建议使用包含简单对象的数组
  • 不要使用
    Array
    函数创建简单数组。改用文字
  • 不要将eval样式字符串用作
    setTimeout
为了回答您的实际问题,让我简单地向您展示这把小提琴:


你所说的“打开框架”是什么意思?请重新写下问题,不清楚你想要实现什么。看到你的代码,它会造成更多的混乱。顺便问一下,您是否尝试过与此处公开的代码不同的内容?