2022年5月
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
無料ブログはココログ

« IE7/IE8で、window.open()で作った子ウィンドウから親ウィンドウを.focus()でアクティブにする。 | トップページ | IE7/IE8で、window.open()で作った子ウィンドウから親ウィンドウを.focus()でアクティブにする。(その2) »

2009年8月17日 (月)

IE7/IE8で、window.open()で作った子ウィンドウを.focus()でアクティブにする。(その2)

もし、複数タブのケースを除外するなら、比較的簡単です。WScript.ShellのAppActivateを使用します。

<html>
<head>
<title>opener</title>
<script language=vbscript>
Option Explicit
Dim win
Sub Activate
win.focus
win.document.focus
If win.document.hasFocus() Then Exit Sub
Dim wShell
Set wShell=CreateObject("WScript.Shell")
If wShell.AppActivate(win.document.title) Then Exit Sub
Dim LocationURL
LocationURL=win.location.href
If Left(LocationURL,8)="file:///" Then LocationURL=Replace(UnEscape(Mid(LocationURL,9)),"/","\")
If LocationURL="about:blank" Then LocationURL="空白のページ"
If wShell.AppActivate(LocationURL) Then Exit Sub
End Sub
</script>
</head>
<body>
<button onclick='Set win=window.open("child app.htm")'>open new tab</button>
<button onclick='Set win=window.open("child app.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='CreateObject("WScript.Shell").AppActivate win.document.title'>AppActivate</button>
<button onclick="Activate">Activate</button>
</body>
</html>

子ウィンドウのタイトルはユニークにしておきます。
ただし、タイトルがタイトルバーに出ないで、URLのままのときがあります。

« IE7/IE8で、window.open()で作った子ウィンドウから親ウィンドウを.focus()でアクティブにする。 | トップページ | IE7/IE8で、window.open()で作った子ウィンドウから親ウィンドウを.focus()でアクティブにする。(その2) »