Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
how to get active IE object
/*
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
You can’t perform that action at this time.