2013-03-14 37 views

回答

2

如果設置了WebViewframeLoadDelegate出口到筆尖文件您的AppleScript類,可以實現AppleScript的Objc相當於WebFrameLoadDelegate的的webView:didStartProvisionalLoadForFrame:方法被告知WebView開始加載新頁面時(這來自WebKit Objective-C Programming Guide - Loading Pages - Displaying the Current URL):

on webView_didStartProvisionalLoadForFrame_(sender, frame) 
    log "webView_didStartProvisionalLoadForFrame_" 

    if frame is equal to sender's mainFrame then 
     set currentURLRequest to frame's provisionalDataSource()'s request 
     log currentURLRequest 

     set theURL to currentURLRequest's mainDocumentURL() 
     log theURL 

     set theURLString to theURL's absoluteString() 
     log theURLString 

     set textField's stringValue to theURLString 

    end if 

end webView_didStartProvisionalLoadForFrame_ 

在此示例代碼,我的文本字段的字符串值設置爲當前的URL,就像一個瀏覽器,當您導航到另一個頁面通常不會。如果需要,您可以隨時將此值存儲在AppleScript property中。

示例項目:WebViewFinaglerAS-Objc.zip