make webview load URL

i’ve been trying to find tihs for ages, but I just want the applescript to tell a web view to load a url
I want the webview to defined by name and the window it is in
webview “view” of window “main”

why is this so hard to find?

Well, for starters, it’s not called “webview”, just “view”. Perhaps this post will help.

Webviews are a relatively “new” technology. I use this (interesting code by Jonathan Nathan):

set URLWithString to call method "URLWithString:" of class "NSURL" with parameter "http://blah.com/"
set requestWithURL to call method "requestWithURL:" of class "NSURLRequest" with parameter URLWithString
set mainframe to call method "mainFrame" of webView
call method "loadRequest:" of mainframe with parameter requestWithURL

Or:

call method "stringByEvaluatingJavaScriptFromString:" of webView with parameter "location.href='http://blah.com/'"

To define the var “webView”, you may:

set webView to view 1 of window 1 --> or whatever

Or (recommended in previous Xcode’s versions), attach to the web view a “awake from nib” event, then:

global webView

on awake from nib theObject
	if theObject's name is "blah" then
		set webView to theObject
	end if
end

im just starting to learn applescript,
and it seems really stupid.
what a confusing code.