javascript 来自 PHP 脚本的 window.open

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11059624/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 11:57:46  来源:igfitidea点击:

window.open from PHP script

phpjavascriptwindow.open

提问by kroolk

Ok, I want to open a new window from inside of a PHP script so I am just echo-ing JS as such:

好的,我想从 PHP 脚本内部打开一个新窗口,所以我只是这样回应 JS:

echo "<script type='text/javascript'>window.open('".configController::$BASE_URL."/view/share.php?u=".$url."');</script>";

I just want a normal window to open that the user can interact with, however ... I get a sickly gazzelle looking window with no menubar, status, etc. It's a pure pop-up ( icky ).

我只想打开一个用户可以与之交互的普通窗口,但是......我得到了一个看起来病态的瞪羚窗口,没有菜单栏、状态等。它是一个纯粹的弹出窗口( icky )。

I've tried supplying the open preferences and enabling all the options, but I still get that featureless window.

我试过提供开放的首选项并启用所有选项,但我仍然得到那个毫无特色的窗口。

Here is the PHP with the options enabled:

这是启用了选项的 PHP:

echo "<script type='text/javascript'>window.open('".configController::$BASE_URL."/view/share.php?u=".$url."',' Share','toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes');</script>";

and here is the JS it generates:

这是它生成的JS:

<script type='text/javascript'>
    window.open('http://localhost:8888/lks/view/share.php?u=www.yahoo.com',' Share','toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes');
</script>

If I use window.open('url here') from a button click that will do what I want ... What's the difference? and ... How can I open just a plain window ?

如果我通过单击按钮使用 window.open('url here') 将执行我想要的操作......有什么区别?和...我怎样才能打开一个普通的窗口?

EDIT:

编辑:

Diving deeper .... I put this page together. The onLoad event will open the lame-o window... clicking the Click Me opens the window properly.

深入研究......我把这个页面放在一起。onLoad 事件将打开蹩脚的窗口...单击 Click Me 打开窗口。

<html>
<head>

    <script type='text/javascript'>
        function popit(){
            //window.open('http://www.yahoo.com','_blank');
            window.open('http://www.yahoo.com','Share','toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,history=yes,resizable=yes');
        }
    </script>
</head>
<body onload="popit()">
    <a href="#" onclick="popit();">CLICK ME</a>
</body>
</html>

EDIT 2:

编辑2:

Found this, I'm guessing the browser is acting weird because a bunch of people in the 1990s decided to abuse JS... The idea was to not interrupt the users experience while sharing, but it looks like I'll have to use the same window and redirect back to the original url when they're done.

发现这个,我猜浏览器的行为很奇怪,因为 1990 年代的一群人决定滥用 JS ......这个想法是在共享时不中断用户体验,但看起来我必须使用相同的窗口并在完成后重定向回原始 url。

window.open not working when attached on onload event in chrome and safari

在 chrome 和 safari 中附加 onload 事件时,window.open 不起作用

EDIT 3:Years later I must clarify that this was not a duplicate question. The original ask was about a window.open from a backend script, at the time that was PHP. When you mark something as a duplicate consider that you're dropping the hammer on the entire subject matter. Just because I link to another S/O answer, that doesn't mean you can throw away the rest of the material.

编辑 3:多年后我必须澄清这不是一个重复的问题。最初的问题是关于后端脚本中的 window.open,当时是 PHP。当您将某些内容标记为重复时,请考虑您正在对整个主题进行抨击。仅仅因为我链接到另一个 S/O 答案,这并不意味着您可以扔掉其余的材料。

回答by Amadan

Third parameter to window.open. Did you try "toolbar=yes, location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes"?

的第三个参数window.open。你试了"toolbar=yes, location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes"吗?

回答by chris

How bout something simple like I used this in a handful of places, works with chrome, firefox, ie, safari, opera.. recently used this in a project I am working on. So it still appears to work.

像我在少数地方使用过的简单的东西如何,可与 chrome、firefox 一起使用,即 safari、opera.. 最近在我正在从事的项目中使用了它。所以它似乎仍然有效。

window.open(url, "_blank");

window.open(url, "_blank");