Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/433.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-检测打开的窗口。我的代码不起作用_Javascript_Jquery_Html - Fatal编程技术网

Javascript-检测打开的窗口。我的代码不起作用

Javascript-检测打开的窗口。我的代码不起作用,javascript,jquery,html,Javascript,Jquery,Html,我不太擅长javascript,但我的代码并不像我希望的那样工作 我试着让别人明白我的意思。 在主页上,我有以下代码: <script type="text/javascript"> <!-- function popitup(url) { newwindow=window.open(url,'name','height=650,width=312'); if (window.focus) {n

我不太擅长javascript,但我的代码并不像我希望的那样工作

我试着让别人明白我的意思。 在主页上,我有以下代码:

    <script type="text/javascript">
        <!--
        function popitup(url) {
           newwindow=window.open(url,'name','height=650,width=312');
           if (window.focus) {newwindow.focus()}
           return false;
        }
        // -->
    </script>

正如你所知,这个代码给我一个312x650的弹出窗口。 然后,我将以下内容放在将打开的链接中:

<a href="" onClick="return popitup('escuchar.php?id=<?=$v['link']?>')"><?=$v['titulo']?></a>

好的,代码工作得很完美,但在这个“弹出窗口”中,我放置了另一个链接,返回主页。 问题是我打开了一个新窗口,然后根据上面的代码,将其放入html弹出javascript代码中,如下所示:

    <script type="text/javascript">
        <!--
        function popitup() {
           url = "index.php"
           newwindow=window.open(url,'Amixer Music');
           if (window.focus) {newwindow.focus()}
        }
        // -->
    </script>

此代码不能100%工作。 我假装发现我打开了一个名为“amixer音乐”的页面,如果没有,就打开这个页面

然后,当我单击弹出窗口中的链接时,我必须返回主页:

<a href="javascript:popitup();" id="volver" title="Ve a la página principal y busca tu música!">Busca tus canciones!</a>

这将打开一个新窗口,并忽略已打开的窗口。 如果我返回单击链接,代码似乎可以工作,因为我没有打开另一个窗口,但我重新加载了在开始时打开的窗口

我的错误示例:
在弹出窗口中,执行以下操作:

function popitup() {
    if(window.opener !== null && window.opener.length && 
        /^http\:\/\/traductoramixer\.x10\.bz\/javascript\/(index.html)?$/i.test(window.opener.location.href)){
        //If the main page is present,
        window.opener.focus();
        window.close();  //optional
    }else{
        //If not,
        var url = "index.php",
            newwindow = window.open(url, 'Amixer Music');
        if (window.focus) { newwindow.focus(); }
    }
}

我相信这会起作用。

不要在中使用空格,例如使用
Amixer\u Music
。你能做一个jsfiddle@Derek朕會功夫, jsFiddle给了我一个关于“POST”的错误。不管怎样,我已经上传到了一个服务器上供你查看。