gpt4 book ai didi

javascript - 在 firefox 和 opera 中打开一个带有 javascript 错误的后台窗口

转载 作者:行者123 更新时间:2023-11-30 05:58:24 24 4
gpt4 key购买 nike

我想用 javascript 在后台打开一个文件。该代码在 chrome 中运行良好,但在 firefox (12) 和 Opera 中新窗口在前台打开。

有人知道我做错了什么吗?

这里是两个文件的代码:

父亲.html:

<html>
<body>
<script>
var son=null;
function openIt(){
son=window.open('son.html','sonpage');
son.blur();
self.focus();
window.focus();
//alert("voy");
return false;
}
</script>
<a href="javascript:void(0)" onClick="openIt(); return false;">Open</a>
<a href="javascript:void(0)" onClick="son.close()">Close</a>
<button type="button" id="play2-video" onclick="son.play()">
play2 video
</button>
<button type="button" id="pause2-video" onclick="son.pausa()">
pause video
</button>
Father Page
</body>

儿子.html:

<html>
<Head>
<script>
function play(){
alert("Play!");
}
function stop(){
alert("Stop!");
}
</script>
</Head>
<Body>
<h1> Son Page</h1>
</Body>

谢谢!

最佳答案

Firefox will only obey requests to raise a window if a security option is set, and it's not set by default. Chrome won't pay attention to focus() requests at all, as far as I can tell. Safari does obey focus() request.

The specific Firefox setting is in the "Tools -> Options" dialog. There's a "Content" tab, and in that there's a checkbox for enabling Javascript. Along with that is an "Advanced" button that brings up another dialog, wherein one finds a checkbox to allow (or disallow) the raising and lowering of windows by page code.

阅读https://stackoverflow.com/a/2533335/643500

试图弄乱代码——没有乐趣

函数只需要:

function openIt(){
son=window.open('son.html','sonpage');
window.focus();
return false;
}

尝试从打开的页面重定向回主页面,看看是否可以这样完成?

此外,查看 JQuery,它可能会处理像 http://api.jquery.com/focusout/ 这样的事件

关于javascript - 在 firefox 和 opera 中打开一个带有 javascript 错误的后台窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10403203/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com