Hi guys I’m assuming I can use a call method for this, but to be honest I find them a bit confusing. I need to get the current URL of a displayed web page. As soon as the user clicks links in the webpage I lose track of the URL. Apparently there’s a method you can call to do this. Can anyone help me out? Thanks a lot for any help…
Hi jamhayes1
Have a nosy at this thread:
http://bbs.applescript.net/viewtopic.php?id=9838
tell application “Firefox”
set the_URL to «class curl» of window 1
end tell
–or
tell application “Safari”
set theURL to the URL of the front document
end tell
Hi,
thanks for the quick reply! Unfortunately I don’t have another browser running. I’m using the Webview in my Applescript Studio application to render web pages. So I need to actually get the current URL programmatically from this Webview. I hope this makes sense? Probably not!
I’m using the following to display the webpages themselves, if that helps? This works fine, but doesn’t let me know what the URL is if the user starts clicking links. (They all load and display correctly)
on loadPage from theURL
set URLWithString to call method “URLWithString:” of class “NSURL” with parameter theURL
set requestWithURL to call method “requestWithURL:” of class “NSURLRequest” with parameter URLWithString
tell window “main”
set mainFrame to call method “mainFrame” of object (view “browser”)
end tell
call method “loadRequest:” of mainFrame with parameter requestWithURL
set contents of text field “UrlTextField” of window “Main” to URLWithString
end loadPage
Jacques,
excellent- that is exactly what I was after! I have to say I’m really impressed by the speed of replies on this board so thanks to both of you for your time.
Jamie
Hi,
Where I must put this code to make it work?
call method "dataSource" of (call method "mainFrame" of (view "browser" of window "Main"))
set currentURL to call method "absoluteString" of (call method "URL" of (call method "initialRequest" of the result))
I’m very new on applescript and I don’t know where I must “paste” this code, my web browser is like jamhayes1’s(same code), I want to know where the user is in every link he clicks…, but I have no idea
Please I need your help.
Thank you very much.