【问题标题】:Setting DOM Element using JS replaces webpage body with value使用 JS 设置 DOM 元素将网页正文替换为值
【发布时间】:2017-01-10 18:31:45
【问题描述】:

我不完全确定这里发生了什么......

1.) 导航到谷歌。

2.) 在地址栏 (Internet Explorer) 中输入

javascript: document.all.q.value = "Hello Google"

我从其他地方学到的其他知识意味着 Google 网站的输入元素应该填写“Hello Google”。

然而相反,对我来说,打开一个完全空白的页面,除了“Hello Google”字样之外完全空白:

<html>
    <head>
        <tile></title>
    </head>
    <body>Hello Google</body>
</html>

奇怪吗?但是,嘿,我想,也许这只是因为语法......所以我尝试使用 getElementById() 代替:

javascript: document.getElementById("lst-ib").value = "Hello Google"

你猜怎么着?和以前一样的“Hello Google”网页...

这是怎么回事?我做错什么了吗?

【问题讨论】:

    标签: javascript internet-explorer autohotkey


    【解决方案1】:

    使用 IE COM Object 操作 Google 搜索页面的示例:

    pwb := ComObjCreate("InternetExplorer.Application") ; Create our Object, pwb holds this reference.
    pwb.Visible := True ; Set our page as visible
    pwb.Navigate("http://google.com") ; Navigate to our website
    while pwb.busy or pwb.ReadyState != 4 ;Wait for page to load
       Sleep 10
    pwb.document.getElementByID("lst-ib").Value := ("Ahk IE COM Objects")
    sleep 1000
    pwb.document.forms[0].submit()
    

    【讨论】:

    • 这对你真的有用吗? :O 当我运行相同的代码并导航到 google 时,IE 对象的引用发生了变化,因此我无法再与之交互......
    • 它对我有用:Win 10,AutoHotkey 版本 1.1.24 这是它运行的视频:sendvid.com/nid7aa7u
    • 嗯...也许这与我们工作中的 IT 安全有关...不过感谢您的代码!会很有用! :)
    • 好吧,我今天尝试了 AHK 脚本。它返回错误Error: 0x80010108 - The object invoked has disconnected from its clients. 完整错误消息:pastebin.com/qWyyga44
    • 现在很明显,您的计算机有问题,而不是代码。在此处查找您的 COM 问题的解决方案:stackoverflow.com/questions/2421188/…
    猜你喜欢
    • 2022-01-01
    • 1970-01-01
    • 2010-10-25
    • 1970-01-01
    • 2018-10-05
    • 1970-01-01
    • 1970-01-01
    • 2011-01-01
    相关资源
    最近更新 更多