AppleScript - 使当前URL更改为JavaScript的脚本

时间:2012-12-15 22:51:25

标签: applescript

这是我目前的代码。

    tell application "Google Chrome" to set the URL of the front document to "Javascript:buy();"

它不允许我使用Javascript,我需要做些什么才能解决这个问题?

1 个答案:

答案 0 :(得分:0)

您可以使用“执行javascript”命令在Chrome中执行javascript。

tell application "Google Chrome"
    activate
    tell window 1 to tell active tab
        set URL to "http://stackoverflow.com/questions/13896927/applescript-script-to-make-current-url-change-to-a-javascript"
        repeat until not loading
            delay 0.2
        end repeat
        set myVar to execute javascript "document.getElementsByClassName('user-details')[0].childNodes[1].text"
    end tell
end tell

return myVar

tell application "Google Chrome"
    activate
    tell window 1 to tell active tab
        set the URL to "Javascript:buy();"
    end tell
end tell