Skip to content

Instantly share code, notes, and snippets.

@Sunitha
Created December 13, 2010 16:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sunitha/739164 to your computer and use it in GitHub Desktop.
Save Sunitha/739164 to your computer and use it in GitHub Desktop.
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