Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/460.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/8/lua/3.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 n秒后不断重定向_Javascript_Php_Redirect_Time - Fatal编程技术网

Javascript n秒后不断重定向

Javascript n秒后不断重定向,javascript,php,redirect,time,Javascript,Php,Redirect,Time,我有一个URL列表,我想在弹出窗口中打开10秒钟。因此,我点击一个按钮,它将打开第一个url,然后等待10秒,播放下一个,依此类推,直到它结束。 我发现了一些我认为有效或有用的功能,我认为我的逻辑是正确的,我认为它应该有效,但也许有更多知识的人可以帮助我。这就是我所拥有的: <script type="text/javascript"> function Redirect(url) { popupWindow = window.open( u

我有一个URL列表,我想在弹出窗口中打开10秒钟。因此,我点击一个按钮,它将打开第一个url,然后等待10秒,播放下一个,依此类推,直到它结束。 我发现了一些我认为有效或有用的功能,我认为我的逻辑是正确的,我认为它应该有效,但也许有更多知识的人可以帮助我。这就是我所拥有的:

<script type="text/javascript"> 
    function Redirect(url) {
        popupWindow = window.open(
        url,'popUpWindow','height=481,width=858,left=10,top=10,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=no')

    }

    function newPopup() {
        <?php 
        $jsSql = mysql_query("SELECT * FROM `songs`"); 
        while($jsRow = mysql_fetch_array($jsSql))
        {?>
            setTimeout('Redirect("<?php
            echo "http://www.youtube.com/embed".$jsRow['url']."?autoplay=1";?>")', 4000);
        <?php
        }
        ?>
    }
</script>

函数重定向(url){
popupWindow=window.open(
url、'popUpWindow'、'height=481,width=858,left=10,top=10,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,Directory=no,status=no')
}
函数newPopup(){
setTimeout('Redirect(“”),4000);
}
更改

setTimeout('Redirect("<?php
  echo "http://www.youtube.com/embed".$jsRow['url']."?autoplay=1";?>")', 4000);
setTimeout('Redirect(“”),4000);

setTimeout(函数(){
重定向(“”),4000);
这将是一个良好的开端


<?php
    $db = new PDO('mysql:host=localhost;dbname=testdb;charset=utf8', 'username', 'password');
?>

<script type="text/javascript"> 
    function Redirect(url) {
        window.open(url, 'popUpWindow', 'height=481,width=858,left=10,top=10,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=no');
    }

    function newPopup() {
        <?php
            $stmt   = $db->query("SELECT * FROM `songs`");
            $songs  = $stmt->fetchAll(PDO::FETCH_OBJ);

            foreach($songs AS $index => $song) {
                printf("setTimeout(Redirect('http://www.youtube.com/embed%s?autoplay=1'), 4000);", $song->url);
            }
        ?>
    }

    // Start
    newPopup();
</script>
函数重定向(url){ 打开(url,'popUpWindow','height=481,width=858,left=10,top=10,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,Directory=no,status=no'); } 函数newPopup(){
我会这样做:

            var data = [];
            var current = 0;
            <?php 
            while($jsRow = mysql_fetch_array($jsSql))
                echo "data.push($jsRow['url']);";
            ?>

            function Redirect()
            {

            }

            function newPopup()
            {
                Redirect(data[current]);    
                current++;
                if (current < data.length)
                    setTimeout(function(){newPopup();}, 10*1000)    
            }
// globals
var songList;

function openNewPopup(url) {
    return window.open(url, 'popUpWindow','height=481,width=858,left=10,top=10,
         resizable=no,scrollbars=no,toolbar=no,menubar=no,
         location=no,directories=no,status=no');
}
function runPopup() {
    var index = 0;
    var popup = openNewPopup(songList[index++]);

    function next() {
        setNewPopupURL(songList[index % songList.length), popup);
        ++index;
        setTimeout(next, 10*1000);
    }
    setTimeout(next, 10*1000);
}
var数据=[];
无功电流=0;

这个问题的关键是,在使用第一个URL打开弹出窗口后,您只需在现有弹出窗口上设置
窗口。位置
,以便它只加载一个新的URL。因此,它类似于:

            var data = [];
            var current = 0;
            <?php 
            while($jsRow = mysql_fetch_array($jsSql))
                echo "data.push($jsRow['url']);";
            ?>

            function Redirect()
            {

            }

            function newPopup()
            {
                Redirect(data[current]);    
                current++;
                if (current < data.length)
                    setTimeout(function(){newPopup();}, 10*1000)    
            }
// globals
var songList;

function openNewPopup(url) {
    return window.open(url, 'popUpWindow','height=481,width=858,left=10,top=10,
         resizable=no,scrollbars=no,toolbar=no,menubar=no,
         location=no,directories=no,status=no');
}
function runPopup() {
    var index = 0;
    var popup = openNewPopup(songList[index++]);

    function next() {
        setNewPopupURL(songList[index % songList.length), popup);
        ++index;
        setTimeout(next, 10*1000);
    }
    setTimeout(next, 10*1000);
}
然后,为了将后续页面加载到现有的弹出窗口中,您只需

function setNewPopupURL(url, popup) {
   popup.location = url;
}
我不太懂PHP,但您希望将歌曲列表放入一个JS变量中,稍后可以循环:

// populate the songList
// the goal here is to do songList.push(songURL) for each song
// to add them all to the songList
<?php 
$jsSql = mysql_query("SELECT * FROM `songs`"); 
while($jsRow = mysql_fetch_array($jsSql))
{?>
    songList.push("<?php
    echo "http://www.youtube.com/embed".$jsRow['url']."?autoplay=1";?>");
<?php
}
?>

mysql_*不推荐使用PDO或MySQLi1)显示呈现的html 2)编写小提琴3)什么不起作用?弹出?重定向?弹出阻止程序处于活动状态?我一直在尝试这些建议,很抱歉我无法提供代码,因为我不在我的工作PC上,但这些建议似乎不起作用。我的想法是javascript和php在dif上不运行以前基本上从未用php输出填充过我的数组?如果这不是问题,我会继续努力解决这个问题。