[英]open a window in background with javascript error in firefox and opera
我想用javascript在后台打開文件。 該代碼在chrome中工作正常,但在Firefox(12)中運行,Opera新窗口在前台打開。
有人知道我錯了嗎?
這里是兩個文件的代碼:
father.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>
son.html:
<html>
<Head>
<script>
function play(){
alert("Play!");
}
function stop(){
alert("Stop!");
}
</script>
</Head>
<Body>
<h1> Son Page</h1>
</Body>
謝謝!
如果設置了安全選項,並且默認情況下未設置該選項,則Firefox將僅服從引發窗口的請求。 據我所知,Chrome根本不會關注focus()請求。 Safari確實遵守focus()請求。
特定的Firefox設置位於“工具->選項”對話框中。 有一個“內容”選項卡,並且其中有一個啟用Javascript的復選框。 隨之而來的是一個“高級”按鈕,該按鈕將彈出另一個對話框,其中將找到一個復選框,以允許(或禁止)通過頁面代碼來升高和降低窗口。
閱讀https://stackoverflow.com/a/2533335/643500
試圖弄亂代碼-不高興
該功能只需要:
function openIt(){
son=window.open('son.html','sonpage');
window.focus();
return false;
}
嘗試從打開的頁面重定向回主頁,看看是否可以通過這種方式完成?
另外,研究一下JQuery,它可能會通過http://api.jquery.com/focusout/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.