Ok, I ran into a brick wall. I’m trying to view a URL in WebView using variables in the URL address. This code works if I just put in a URL for “set theURL to ” in the code, but whenever I try to add variables, nothing happens. I don’t get an error message, but all that shows up in WebView is a white page.
So I know I must not be defining my variables in the right place or right way, but I’ve been spending the last 2 hours playing around with them to no avail. Any suggestions?
Here’s the code
on clicked theObject
GetURL()
end clicked
on end editing theObject
GetURL()
end end editing
on GetURL()
tell window "main"
set theStreet to (the content of text field "theStreet") as string
set postalcode to (the content of text field "postalCode") as string
set stateprovince to (the content of text field "stateProvince") as string
set theURL to "http://www.whitepages.com/search/ReverseAddress?street=" & theStreet & "&city_zip=" & postalcode & "&state_id=" & stateprovince
try
set URLWithString to call method "URLWithString:" of class "NSURL" with parameter theURL
set requestWithURL to call method "requestWithURL:" of class "NSURLRequest" with parameter URLWithString
set mainFrame to call method "mainFrame" of object (view "browser" of window "main")
call method "loadRequest:" of mainFrame with parameter requestWithURL
end try
end tell
end GetURL
Moving to AS Studio & Xcode… (Thanks, hendo13)
sorry about that, should’ve checked which forum I was posting in more closely
Hi George,
there is one mistake in this line:
set mainFrame to call method "mainFrame" of object (view "browser" of window "main")
which results that you address view “browser” of window “main” of window “main”
But I don’t think that’s your problem …
I am not 100% sure but I think the problem has something to do with illegal characters in your address string (Unicode??) since the method "URLWithString resulted nothin in your script. I was able to solve the problem here by adding a further call method:
on GetURL()
tell window "main"
set theStreet to (the content of text field "theStreet")
set postalcode to (the content of text field "postalCode")
set stateprovince to (the content of text field "stateProvince")
set theURL to "http://www.whitepages.com/search/ReverseAddress?street=" & theStreet & "&city_zip=" & postalcode & "&state_id=" & stateprovince as text
try
set newString to (call method "stringByAddingPercentEscapesUsingEncoding:" of theURL with parameter 30)
set URLWithString to call method "URLWithString:" of class "NSURL" with parameter newString
set requestWithURL to call method "requestWithURL:" of class "NSURLRequest" with parameter URLWithString
set mainFrame to call method "mainFrame" of object (view "browser")
call method "loadRequest:" of mainFrame with parameter requestWithURL
on error errmsg
log errmsg
end try
end tell
end GetURL
hope that helps …
D.
Thank you, Dominik. That worked perfectly!