Created
December 13, 2010 16:19
-
-
Save Sunitha/739164 to your computer and use it in GitHub Desktop.
how to get active IE object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
IE6まではJScriptでは以下のようにアクティブウィンドウを取得できましたが、IE7以降はできなくなりました。 | |
var Shell = new ActiveXObject( "Shell.Application" ); | |
var ie = Shell.Windows().Item(); | |
それでも何とか取りたかったので作ってみました。 | |
これを使うと、ブックマークレットのようでいて文字制限が無いのを作れます。 | |
*/ | |
var getActiveHWND = function(){ | |
//SFC miniが無いと動きません(http://sourceforge.jp/projects/sfcmini/releases/) | |
var GetForegroundWindow = new ActiveXObject("SfcMini.DynaCall"); | |
GetForegroundWindow.Declare("user32","GetForegroundWindow"); | |
return GetForegroundWindow(); | |
}; | |
var getShellWindows = function(hwnd){ | |
var shell = new ActiveXObject( "Shell.Application" ); | |
var shellWindows = shell.Windows(); | |
var windows = []; | |
for(var i=0;i<shellWindows.Count;i++){ | |
var win = shellWindows.Item(i); | |
if(0<=win.Path.indexOf("Internet Explorer")){ | |
if(win.hwnd == hwnd){ | |
windows.push(win); | |
} | |
} | |
} | |
return windows; | |
}; | |
var getAcitiveWindow = function(){ | |
var windows = getShellWindows(getActiveHWND()); | |
for(var i=0;i<windows.length;i++){ | |
var text = String(i); | |
windows[i].StatusText = text; | |
if(windows[i].StatusText == text){ | |
return windows[i].Document.parentWindow; | |
} | |
} | |
}; | |
var window = getAcitiveWindow() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment