IE7/IE8で、window.open()で作った子ウィンドウから親ウィンドウを.focus()でアクティブにする。
IE7/IE8では、「常に新しいタブでポップアップを開く」等の設定により、window.open()が新しいタブで開かれます。
そうでなくても、親ウィンドウが複数タブの場合があります。
そのような場合、子ウィンドウから親ウィンドウを.focus()でアクティブにするのは困難です。
child.htm
<html>
<head>
<object id=ShellWindows classid=clsid:9BA05972-F6A8-11CF-A442-00A0C90A8F39></object>
<object id=wShell classid=clsid:72C24DD5-D70A-438B-8A42-98424B88AFB8></object>
<script language=vbscript>
Option Explicit
Dim n
Sub TabActivate
Dim ie,ix
For Each ie In ShellWindows
If TypeName(ie.Document)<>"HTMLDocument" Then
ElseIf ie.Document.parentWindow Is opener Then
Exit For
End If
Next
If IsEmpty(ie) Then
MsgBox "Not Found 1"
Exit Sub
End If
opener.focus
opener.document.focus
If opener.document.hasFocus() Then Exit Sub
If AppActivate(ie) Then Exit Sub
For Each ix In ShellWindows
If ix.HWND=ie.HWND Then
ix.Document.focus
If ix.Document.hasFocus() Then Exit For
If AppActivate(ix) Then Exit For
End If
Next
If IsEmpty(ix) Then
MsgBox "Not Found 2"
Exit Sub
End If
n=0
NextTab
End Sub
Sub NextTab
If opener.document.hasFocus() Then Exit Sub
If n<ShellWindows.Count Then
n=n+1
wShell.SendKeys "^{tab}"
setTimeout "NextTab",100
Exit Sub
End If
MsgBox "Not Found 3"
End Sub
Function AppActivate(ie)
AppActivate=True
If wShell.AppActivate(ie.Document.title) Then Exit Function
Dim LocationURL
LocationURL=ie.LocationURL
If Left(LocationURL,8)="file:///" Then LocationURL=Replace(UnEscape(Mid(LocationURL,9)),"/","\")
If LocationURL="about:blank" Then LocationURL="空白のページ"
If wShell.AppActivate(LocationURL) Then Exit Function
AppActivate=False
End Function
</script>
</head>
<body>
<button onclick="opener.focus">opener.focus</button>
<button onclick="opener.document.focus">opener.document.focus</button>
<button onclick="TabActivate">TabActivate</button>
</body>
</html>
« IE7/IE8で、IEオブジェクトがアクティブなタブか?を判定する。 | トップページ | IE7/IE8で、window.open()で作った子ウィンドウを.focus()でアクティブにする。(その2) »