A.htmlからB.htmlを<a target=”_blank”>で開きます。その後、B.html中の<a onClick=””>で、A.htmlを開いていたウィンドウにC.htmlを表示させ、C.htmlのウィンドウにフォーカスしたいのです。このとき、A.htmlを開いていたウィンドウが既に閉じられていたら、target=”_blank”でC.htmlを表示します。
実際に動作するコードを一番最初提示してくださった方に100ポイント差し上げます。
それ以外の方にももちろん相応のポイントを差し上げます。
よろしくお願いします。
以下の3つのファイルで試してみてください。
私が勘違いしてなければ以下でOKかと思います。
a.html
<html>
<head>
</head>
<body>
<a target=”_blank” href=”b.html”>test</a>
</body>
</html>
b.html
<html>
<head>
<script language=”JavaScript”>
function win_open(){
if(!window.opener.closed){
window.opener.location.href = ”c.html”
}else{
window.opener = window.open(”c.html”)
}
}
</script>
</head>
<body>
<a href=”#” onclick=”win_open()”>c.html</a>
</body>
</html>
c.html
<html>
<head>
</head>
<body>
hello
</body>
</html>
B.html の内容です。
<script type="text/javascript">
<!--
function opener_check(url){
if (window.opener) {
window.onerror=function(){return(true);}
window.opener.location.href=url;
window.opener.focus();
window.onerror=function(){return(false);}
return(false);
} else {
return(true);
}
}
//-->
</script>
<p><a href="./C.html" onclick="return(opener_check(this.href));" target="_blank">C</a></p>
ブラウザによってはうまく動かないかもしれません。
ありがとうございます。
> ブラウザによってはうまく動かないかもしれません。
程度によってはそれでは困ってしまいます。メジャーなプラットフォームのメジャーなブラウザをカバーしていれば結構です。
フォーカス忘れてました。
以下の関数と差し替えてください。
function win_open(){
if(!window.opener.closed){
window.opener.location.href = ”c.html”;
}else{
window.opener = window.open(”c.html”);
}
window.opener.focus();
}
ありがとうございます。
実際に試してみたところ動作しました。
質問を終了したいと思います。
ありがとうございます。ざっと見てみました。
focus()がないようですが・・・。