找回密码
 加入
搜索
查看: 4415|回复: 5

[IE类操作] 如何让嵌入的IE浏览器自动滚动到最后?

  [复制链接]
发表于 2013-12-5 23:37:49 | 显示全部楼层 |阅读模式
本帖最后由 mbdnmt 于 2013-12-5 23:41 编辑

采用GUICtrlCreateObj方式创建嵌入的IE,如何让显示的网页自动滚动到最后?

要载入的网页是随时间不断增加新的行的(类似于聊天记录),如何操作可以让嵌入的IE不断刷新,并且自动滚动到最后(相当于滚动到最后一条消息)

这是例子里嵌入IE的例子
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Example()

; 简单示例: 嵌入Internet Explorer对象到 AutoIt GUI
;
; 参见: http://msdn.microsoft.com/workshop/browser/webbrowser/reference/objects/internetexplorer.asp
Func Example()
    Local $oIE, $GUI_Button_Back, $GUI_Button_Forward
    Local $GUI_Button_Home, $GUI_Button_Stop, $msg

    $oIE = ObjCreate("Shell.Explorer.2")

    ; 为输出创建一个简单的 GUI
    GUICreate("嵌入 Web 控件测试", 640, 580, (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS, $WS_CLIPCHILDREN))
    GUICtrlCreateObj($oIE, 10, 40, 600, 360)
    $GUI_Button_Back = GUICtrlCreateButton("返回", 10, 420, 100, 30)
    $GUI_Button_Forward = GUICtrlCreateButton("向前", 120, 420, 100, 30)
    $GUI_Button_Home = GUICtrlCreateButton("主页", 230, 420, 100, 30)
    $GUI_Button_Stop = GUICtrlCreateButton("停止", 330, 420, 100, 30)

    GUISetState() ;显示 GUI

    $oIE.navigate("http://www.autoitx.com")

    ; 等待用户关闭窗口
    While 1
        $msg = GUIGetMsg()

        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $GUI_Button_Home
                $oIE.navigate("http://www.autoitx.com")
            Case $msg = $GUI_Button_Back
                $oIE.GoBack
            Case $msg = $GUI_Button_Forward
                $oIE.GoForward
            Case $msg = $GUI_Button_Stop
                $oIE.Stop
        EndSelect

    WEnd

    GUIDelete()
EndFunc   ;==>Example
发表于 2013-12-6 08:46:54 | 显示全部楼层
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Example()

; 简单示例: 嵌入Internet Explorer对象到 AutoIt GUI
;
; 参见: http://msdn.microsoft.com/workshop/browser/webbrowser/reference/objects/internetexplorer.asp
Func Example()
    Local $oIE, $GUI_Button_Back, $GUI_Button_Forward
    Local $GUI_Button_Home, $GUI_Button_Stop, $msg

    $oIE = ObjCreate("Shell.Explorer.2")

    ; 为输出创建一个简单的 GUI
    GUICreate("嵌入 Web 控件测试", 640, 580, (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS, $WS_CLIPCHILDREN))
    GUICtrlCreateObj($oIE, 10, 40, 600, 360)
    $GUI_Button_Back = GUICtrlCreateButton("返回", 10, 420, 100, 30)
    $GUI_Button_Forward = GUICtrlCreateButton("向前", 120, 420, 100, 30)
    $GUI_Button_Home = GUICtrlCreateButton("主页", 230, 420, 100, 30)
    $GUI_Button_Stop = GUICtrlCreateButton("停止", 330, 420, 100, 30)

    GUISetState() ;显示 GUI

    $oIE.navigate("http://www.autoitx.com")
        Sleep(100)
        While $oIE.readystate<>4
                Sleep(100)
        WEnd
        $oIE.document.parentwindow.execscript("javascript:window.scrollTo(0,document.body.scrollHeight);")

    ; 等待用户关闭窗口
    While 1
        $msg = GUIGetMsg()

        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $GUI_Button_Home
                $oIE.navigate("http://www.autoitx.com")
            Case $msg = $GUI_Button_Back
                $oIE.GoBack
            Case $msg = $GUI_Button_Forward
                $oIE.GoForward
            Case $msg = $GUI_Button_Stop
                $oIE.Stop
        EndSelect

    WEnd

    GUIDelete()
EndFunc   ;==>Example
滚动到最后试一下这个,估计要再加个判断才能实现你说的不断增加不断滚动
 楼主| 发表于 2013-12-7 22:58:07 | 显示全部楼层
回复 2# kevinch

非常感谢,要的就是这句

$oIE.document.parentwindow.execscript("javascript:window.scrollTo(0,document.body.scrollHeight);")

如何知道$oIE.都有那些方法呢?
发表于 2013-12-26 03:44:53 | 显示全部楼层
mark学习一下,以后必须要用到的
发表于 2013-12-26 07:06:27 | 显示全部楼层
不错!楼主完善完善
发表于 2013-12-26 09:53:28 | 显示全部楼层
非常感谢,学习学习。留到后头用
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-3 03:02 , Processed in 0.075754 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表