开发者

Calling an AJAX function declared as a VAR, using Applescript

开发者 https://www.devze.com 2023-04-06 23:19 出处:网络
I am trying to run a javascript code inside a page using Applescript. The AJAX function was declared in 开发者_StackOverflowjavascript using something like this

I am trying to run a javascript code inside a page using Applescript.

The AJAX function was declared in 开发者_StackOverflowjavascript using something like this

var myFunction = function () {
  // bla bla... here goes the code...
}

I have tried this in Applescript:

do JavaScript "document.myFunction()"

but the code is not running.

any clues? thanks.


Global variables are created as properties of the global object (window, for web browsers). Thus window.myFunction would be the proper reference. However, you don't need to specify the global object.

The key is that you must specify in AppleScript the target tab or document. For example:

tell application "Safari"
    do JavaScript "myFunction()" in current tab of window 1
end tell
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号