2009-04-08 24 views
2

Internet Explorer/Firefoxでスクロールバーの位置を取得/設定する方法はありますか? 私はではありませんは、HTML/ASP/Javascriptコード内からではなく、(例えばWinAPIを使用して)ブラウザ外のアプリケーションから、そしてBHOを使用せずにそうしたいと考えています。ブラウザのスクロールバーの位置を取得/設定する方法(IE/Firefox/...)?

私が今行った検索からは、不可能と思われるので、ここで最後の試行として質問を削除します。

答えて

2

Internet Explorerの場合は、COMオートメーションを使用して、アクティブなInternet Explorerのすべてのウィンドウ/タブを列挙し、ウィンドウ/タブに表示されているドキュメントのDOMツリーにアクセスしてスクロール位置にアクセスし、読み取ることができます。

次のサンプルコードでは、Delphiをプログラミング言語として使用しています。 http://msdn.microsoft.com/en-us/library/bb773974(VS.85).aspx

:メカニズムは、ここで起動し、ドキュメントについて
var 
    ShWindows: ShellWindows; 
    InetExplorer: InternetExplorer; 
    Count: Integer; 
    I: Integer; 
    HTMLDocument: IHTMLDocument2; 
    Elem: IHTMLElement2; 
    ScrollPosY: Integer; 
begin 
    // Create ShellWindows Object 
    SHWindows:= CoShellWindows.Create; 

    // Number of explorer windows/tabs (win explorer and ie) 
    Count:= ShWindows.Count; 
    ShowMessage(Format('There are %d explorer windows open.', [Count])); 

    // For all windows/tabs 
    for I:= 0 to (Count - 1) do 
    begin 
    // Get as InetExplorer interface 
    InetExplorer:= SHWindows.item(I) as InternetExplorer; 

    // Check to see if this explorer window contains a web document 
    if Supports(InetExplorer.Document, IHTMLDocument2, HTMLDocument) then 
    begin 
     // Get body Element 
     Elem:= HTMLDocument.body as IHTMLElement2; 
     // Read vertical scroll position 
     ScrollPosY:= Elem.scrollTop; 

     // If this is 0 so far, maybe there is a scroll position in root element 
     if ScrollPosY = 0 then 
     begin 
     Elem:= HTMLDocument.body.parentElement as IHTMLElement2; 
     ScrollPosY:= Elem.scrollTop; 
     end; 

     // Display 
     ShowMessage(IntToStr(Elem.scrollTop)); 
    end; 
    end; 
end; 

C++、VBやC#

に似ています
関連する問題