IE7/IE8で、window.open()で作った子ウィンドウを.focus()でアクティブにする。(その3)
IE7/IE8では、「常に新しいタブでポップアップを開く」等の設定により、window.open()が新しいタブで開かれます。
そのような場合は、子ウィンドウを.focus()でアクティブにするのは困難です。
外部オブジェクトを使えば、なんとかなりますが、それも大変です。
そこで、スクリプトだけの簡便な方法です。MsgBox(vbSystemModal)を利用します。
<html>
<head>
<script language=vbscript>
Dim win
Sub MsgActivate
win.focus
win.document.focus
If win.document.hasFocus() Then Exit Sub
win.setTimeout "MsgBox ""focus moving..."",vbSystemModal",0,"vbscript"
End Sub
</script>
</head>
<body>
<button onclick='Set win=window.open("child msg.htm")'>open new tab</button>
<button onclick='Set win=window.open("child msg.htm","_blank","resizable=no")'>open new window</button>
<button onclick="win.focus">win.focus</button>
<button onclick="win.document.focus">win.document.focus</button>
<button onclick='win.setTimeout "MsgBox ""focus moving..."",vbSystemModal",0,"vbscript"'>MsgBox</button>
<button onclick="MsgActivate">MsgActivate</button>
</body>
</html>
子ウィンドウがバックグラウンド タブの場合は、そのタブバーが点滅します。
« IE7/IE8で、window.open()で作った子ウィンドウから親ウィンドウを.focus()でアクティブにする。(その2) | トップページ | IE7/IE8で、window.open()で作った子ウィンドウから親ウィンドウを.focus()でアクティブにする。(その3) »