Web View Item in a Box

Hi Folks,

has anybody managed to bring a Web View in a Box?

set webView to view "browse" of window "main"
set URLWithString to call method "URLWithString:" of class "NSURL" with parameter "http://www.someplace.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

This code is working as expected - but
when I put the webview in a box it is crashing when
I change

set webView to view "browse" of box "box" of window "main"

Thanks for your Feedback!


Why do you want a webview in a box? Why not just put it in a webview?
you could just use this code to insert it into a webview but im not sure about a box…(what is a box?)

(* Tell the browser to load a page *)
loadPage from "http://www.cns-world.com"
(* The browser config cod: *)
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 "page"
		set mainFrame to call method "mainFrame" of object (view "browser")
	end tell
	call method "loadRequest:" of mainFrame with parameter requestWithURL
end loadPage

Hi Stefan,

I tried it here (10.4.10/MacBook Pro 2.33 GHz Intel Core Duo) but could not reproduce your crash problem. The webview is working - in and outside of a box


Your code works fine for me.

When you say crashing, do you really mean your application unexpectedly terminates? That is, would you be more specific as to what is actually happening?

Hi Folks,

the reason for putting a webview into a box is the following:

I am programming a quiz:

The first question is “Webbrowsing”, second is “Downloading” and third is “Emailing” - if I am
using boxes it is easier for me to simple enable or disable the whole boxes (box 2 and 3 are disabled while box 1 is enabled - or 1 and 2 are
disabled while 3 is enabled)

Box - NSbox (Interface Builder) - its similar to a tab view

The Application is not real crashing when I am using the box - it is simply not displaying any webpage…

Best Regards and thanks a lot for your help!


Hi Dominik,

could you please post the code for displaying a webview inside a box?

Thanks a lot,


Are you ever using user input to define what page to load?

I also see no problems with your examples. The error has to be somewhere else in your code. Are you including the “http://” before the web address you’re trying to pass to it? You need to pass a valid url string, including the protocol.

There shouldn’t be any code for displaying a webview in a box… that’s all taken care of in IB. As I said, you’re obviously not doing something else properly, such as passing a valid url or referencing the view correctly. Are you sure the names of your objects are right in your code?

One thing I might recommend, is to set up a persistent reference to the web view as soon as it awakens from nib. In the awakeFromNib handler below (connected to the web view in IB, of course), I grab a reference to the web view and save it in a property variable. This makes having to reference the object correctly unnecessary altogether, as the object returned in “theObject” is definitely going to be the correct one. Then, any time you want to mess with the web view, just pass your commands to that reference or pass the reference as an argument to a handler or method.

Both of the following methods of gaining a valid reference to my web view worked for me…

property myWebView : null

on awake from nib theObject
	if name of theObject is "myWebView" then
		set myWebView to theObject
	end if
end awake from nib

on will finish launching theObject
	set myWebView to view "myWebView" of box "myBox" of window "myWindow"
end will finish launching

I’m guessing you missed something simple somewhere, or you’re not passing a valid url.

Hi Folks,

sorry for stealing your time, but now it is working… :slight_smile:

Thanks for your support and best regards,