view webpage

How do i make it so i can view a website? i have the safari thing set on the window but don’t know the code to view sites on it. i tried open location, that didn’t work… maybe i have it set to the wrong thing?

Hi,

something like this


tell window "myWindow"
	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
end tell

theURL contains the URL (format http://.)
view “browser” is the web view

hmmm unless i’m linkin this wrong it won’t work… i changed thURL to mine.

Hi

ive been using this for a while now, you may be able to adapt to suit your purpose, works well

on clicked theObject
	if name of theObject is "GOOGLE" then
		my load_webpage("http://www.google.co.nz/")
		--------
	else if name of theObject is "getnew" then
		set _getpage to contents of text field "URL" of window "main" as string
		my load_webpage(_getpage)
	end if
end clicked

on load_webpage(this_URL)
	try
		set URLWithString to call method "URLWithString:" of class "NSURL" with parameter this_URL
		set request_URL to call method "requestWithURL:" of class "NSURLRequest" with parameter URLWithString
		set main_Frame to call method "mainFrame" of object (view "webView" of window "main")
		call method "loadRequest:" of main_Frame with parameter request_URL
	end try
end load_webpage

Budgie

What’s there to click? i want a window to just automatically appear and show a website. :slight_smile: sorry for the confusion

maybe try “on will open theObject” or “on awake from nib theObject”

on will open theObject
	my load_webpage("http://www.google.co.nz/")
	--------
end will open

on load_webpage(this_URL)
	try
		set URLWithString to call method "URLWithString:" of class "NSURL" with parameter this_URL
		set request_URL to call method "requestWithURL:" of class "NSURLRequest" with parameter URLWithString
		set main_Frame to call method "mainFrame" of object (view "webView" of window "main")
		call method "loadRequest:" of main_Frame with parameter request_URL
	end try
end load_webpage

Budgie

have you also adjusted the reference of your web view ?

Eh…i dunno… lol what i need is for a window to open and view a website. I added the safari Web browser thing to the window. i just need to add a code. Since coca code is dam hard i think, i came here to see if anyone new the code to view websites.