I’ve made a browser in AppleScript studio that allows javascript pop-ups. (see www.macdevcenter.com/pub/a/mac/2004/05/28/webkit.html)
Everything is working fine, but I want my Browser to have two tabs on it so I can switch between 2 different websites. I’ve set up all my outlets correctly for this to work on just one window, but can’t figure out how to have multiple browser windows open.
Here’s the correct MyDocument.m and MyDocument.h codes for just one window browser:
MyDocument.m
#import <Cocoa/Cocoa.h>
#import <WebKit/WebView.h>
@interface MyDocument : NSDocument
{
IBOutlet id urlString;
IBOutlet WebView *webView;
}
- (IBAction)connectURL:(id)sender;
@end
MyDocument.h
#import "MyDocument.h"
@implementation MyDocument
- (id)init
{
self = [super init];
if (self) {
// Add your subclass-specific initialization here.
// If an error occurs here, send a [self release] message and return nil.
}
return self;
}
- (NSString *)windowNibName
{
// Override returning the nib file name of the document
// If you need to use a subclass of NSWindowController or if your document supports multiple NSWindowControllers, you should remove this method and override -makeWindowControllers instead.
return @"MyDocument";
}
- (void)windowControllerDidLoadNib:(NSWindowController *) aController
{
[super windowControllerDidLoadNib:aController];
// Add any code here that needs to be executed once the windowController has loaded the document's window.
[webView setUIDelegate:self];
[webView setGroupName:@"MyDocument"];
[webView setUIDelegate:self];
}
- (NSData *)dataRepresentationOfType:(NSString *)aType
{
// Insert code here to write your document from the given data. You can also choose to override -fileWrapperRepresentationOfType: or -writeToFile:ofType: instead.
// For applications targeted for Tiger or later systems, you should use the new Tiger API -dataOfType:error:. In this case you can also choose to override -writeToURL:ofType:error:, -fileWrapperOfType:error:, or -writeToURL:ofType:forSaveOperation:originalContentsURL:error: instead.
return nil;
}
- (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType
{
// Insert code here to read your document from the given data. You can also choose to override -loadFileWrapperRepresentation:ofType: or -readFromFile:ofType: instead.
// For applications targeted for Tiger or later systems, you should use the new Tiger API readFromData:ofType:error:. In this case you can also choose to override -readFromURL:ofType:error: or -readFromFileWrapper:ofType:error: instead.
return YES;
}
- (IBAction)connectURL:(id)sender{
[urlString setStringValue:[sender stringValue]];
[[webView mainFrame] loadRequest:
[NSURLRequest requestWithURL:
[NSURL URLWithString:
[sender stringValue]]]];
}
- (WebView *)webView:(WebView *)sender
createWebViewWithRequest:
(NSURLRequest *)request
{
id myDocument = [
[NSDocumentController
sharedDocumentController]
openUntitledDocumentOfType:
@"DocumentType"
display:YES];
[[[myDocument webView] mainFrame]
loadRequest:request];
return [myDocument webView];
}
- (void)webViewShow:(WebView *)sender
{
id myDocument = [[NSDocumentController
sharedDocumentController]
documentForWindow:
[sender window]];
[myDocument showWindows];
}
@end
I know nothing about Objective C and I’ve been playing around for hours trying to figure out how to add more than one browser to my application. I’m assuming this is something simple, I just need to know how to alter the Obj C codes in my .h and .m files. Any Objc C vets out there that can point a newbie in the right direction?