0
我在Xcode中有一個webView,並且在瀏覽幾秒鐘之後,我希望能夠獲取Web視圖的當前URL。我搜索了四周,但我無法找到如何。任何幫助,將不勝感激!如何使用AppleScriptObjC獲取Xcode中Web視圖的當前網址?
我在Xcode中有一個webView,並且在瀏覽幾秒鐘之後,我希望能夠獲取Web視圖的當前URL。我搜索了四周,但我無法找到如何。任何幫助,將不勝感激!如何使用AppleScriptObjC獲取Xcode中Web視圖的當前網址?
如果設置了WebView
的frameLoadDelegate
出口到筆尖文件您的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
中。