Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.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 Onclick window.open弹出窗口在Firefox和Safari中不起作用_Javascript_Cross Browser - Fatal编程技术网

Javascript Onclick window.open弹出窗口在Firefox和Safari中不起作用

Javascript Onclick window.open弹出窗口在Firefox和Safari中不起作用,javascript,cross-browser,Javascript,Cross Browser,在(密码为“WS”,不带引号)上,我创建了一个带有插件的网格(UberGrid) 为了使每个单元格成为弹出窗口,我在Wordpress页面中添加了以下代码: <script type="text/javascript"> function popWin(url) { var thePopCode = window.open(url,'','height=800, width=1000, top=500, left=200, scrollable=yes, menubar=ye

在(密码为“WS”,不带引号)上,我创建了一个带有插件的网格(UberGrid)

为了使每个单元格成为弹出窗口,我在Wordpress页面中添加了以下代码:

<script type="text/javascript">
function popWin(url)
{
    var thePopCode = window.open(url,'','height=800, width=1000, top=500, left=200, scrollable=yes, menubar=yes, resizable=yes');
    if (window.focus) 
    {
        thePopCode.focus();
    }
}
</script>
它在Google Chrome中运行良好,但在Firefox或Safari中没有结果。

请尝试以下代码:

function popwin(url) {
window.open('', url, 'height=800, width=1000, top=500, left=200, scrollable=yes, menubar=yes, resizable=yes');
url.target =url;
}
对于链接,使用相同的代码

javascript: onclick=popWin('http://www.weybridgestrategies.com/team/debra-porter-president-ceo'); return (false);

看看生成了什么HTML:

<a class="uber-grid-hover" href="onclick=popWin(&#039;http://www.weybridgestrategies.com/team/debra-porter-president-ceo&#039;); return (false);"  >
使用此脚本,您应该不再需要为每个锚点创建
onclick
属性。只要把它放到你的wordpress源代码中,它就可以正常工作了

现在只需使用
class=“uber grid hover”
创建
,这是必需的,以便jQuery可以轻松选择悬停,然后您需要
href
,还可以包括
target=“\u blank”
,以便非javascript用户也可以在新窗口中使用该页面

<a class="uber-grid-hover" target="_blank"
   href="http://www.weybridgestrategies.com/team/debra-porter-president-ceo">


我在网格上方添加了一个文本链接:“onclick=”popWin(this.href);返回(假);“>TestLink此选项适用于所有浏览器。为了便于讨论,除非有特定原因需要指定窗口大小和位置等,否则您确实应该将
target=“\u blank”
添加到您的
标记中。90%的用户将永远不会看到弹出窗口,而是会得到一个”嘿,我们按您计划的方式阻止了来自他们浏览器的“弹出”消息。这也是一个公认的惯例,即如果您不需要持久数据(帮助、说明等)的弹出窗口,您应该保持链接“正常”(即没有弹出窗口)大多数情况下。只是一些友好的建议;)嗨,布莱恩,非常感谢你的输入。你说得太对了!有没有办法编写这样的代码:如果弹出窗口被阻止,请执行target=“\u blank”"? 非常感谢你!Claudia关于同一主题,这里有很多问题,但简而言之,您希望查看变量
的结果以确定窗口是否成功打开。谢谢Brian!我将通读这篇文章。非常感谢你,艾哈迈德,但不幸的是,现在它在Chrome中不再工作,在其他浏览器中仍然不工作。。。还有别的想法吗?非常感谢你!嗨,梅塔丁。我读了好几遍你的评论(我是一个绝对的初学者…),但现在我开始明白了。你能告诉我我不需要“inline onclick=”是什么意思吗?尽管我很害怕,但我肯定会看看jQuery UI的内部!利贝·格鲁塞!ClaudiSorry更新了10次,现在应该是正确的;)顺便说一句,作为初学者,不要使用原始javascript,因为浏览器的怪癖和人们在开发环境中看不到与您相同的结果,您会感到头疼,最好使用jquery一段时间,您说jquery UI更容易吗?太好了!我要试试看!非常感谢你!Metadings,刚刚看到了你的代码。很抱歉问:我能把它发布到Wordpress页面吗?我现在应该用什么来代替javascript作为锚:onclick=popWin(');返回(假)?非常感谢你的帮助。我真的很感激!克劳迪亚:你真是个大帮手。令人惊叹的!我还是做错事。添加“>作为单元格内的链接,但不起作用。知道为什么吗?或者我不应该这样做?
<a class="uber-grid-hover" href="http://www.weybridgestrategies.com/team/debra-porter-president-ceo"
   onclick="popWin('http://www.weybridgestrategies.com/team/debra-porter-president-ceo'); return false;">
<script type="text/javascript">
function popWin(url)
{
  var thePopCode = window.open(url,'','height=800, width=1000, top=500, left=200,scrollable=yes, menubar=yes, resizable=yes');
  if (window.focus) {
    thePopCode.focus();
  }
}

jQuery(document).ready(function ($) {
    // here is your HTML DOM ready

    // create an onclick event for every a.uber-grid-hover
    $("a.uber-grid-hover").click(function (event) {

        event.preventDefault(); // this is "like" return false

        // this get's the href from your anchor, using jQuery sugar
        var url = $(this).attr("href");

        // call your fun
        popWin(url);

    });

});

</script>
<a class="uber-grid-hover" target="_blank"
   href="http://www.weybridgestrategies.com/team/debra-porter-president-ceo">