• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
App crash after javascript called window closes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

App crash after javascript called window closes


  • Subject: App crash after javascript called window closes
  • From: Alan Klein <email@hidden>
  • Date: Tue, 2 Aug 2005 10:18:48 -0700 (PDT)

I have this simple web browser program that seems to
have a problem with javascript called windows. When I
close a window that was invoked by a javascript
command, my program crashes.

The program was originally a project I saw elsewhere
on the net, but I have made some changes to it. I did
remove most of my changes, as the problem exists at
the level of code that I have below.
Here is the code that I am using:

Here is my header:
#import <Cocoa/Cocoa.h>
#import <WebKit/WebKit.h>
#import <WebKit/WebFrame.h>
#import <WebKit/WebDataSource.h>
#import <WebKit/WebPolicyDelegate.h>

@interface MyDocument : NSDocument
{
IBOutlet id urlString;
IBOutlet WebView *webView;
}
-(void)setDefaultHomepage:(NSString*)homepage;
-(NSString *)getDefaultHomepage;
- (IBAction)connectURL:(id)sender;

@end

Here is the mydocument.m file:

#import "MyDocument.h"


static NSString *defaultHP
=@"http://lists.apple.com/mailman/listinfo/cocoa-dev";;

@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"];
	[urlString setStringValue:defaultHP];
	[[webView mainFrame] loadRequest:
	[NSURLRequest requestWithURL:
	[NSURL URLWithString:defaultHP]]];
	[webView setFrameLoadDelegate: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.
    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.
    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)webView:(WebView *)sender
didReceiveTitle:(NSString *)title forFrame:(WebFrame
*)frame
{
    // Report feedback only for the main frame.
    if (frame == [sender mainFrame]){
        [[sender window] setTitle:title];

    }
}

- (void)webViewShow:(WebView *)sender
{
    id myDocument = [[NSDocumentController
                        sharedDocumentController]
                        documentForWindow:
                            [sender window]];
    [myDocument showWindows];
}



- (void)webView:(WebView *)sender
didStartProvisionalLoadForFrame:
(WebFrame *)frame

{
//Add what to do as page begins to load.
// Only report feedback for the main frame.
if (frame == [sender mainFrame]){
NSString *url = [[[
[frame provisionalDataSource]
request] URL] absoluteString];
[urlString setStringValue:url];
}
}


 -(id)webView{
    return webView;
}

-(void)setDefaultHomepage:(NSString*)homepage{
    defaultHP = homepage;
}

-(NSString *)getDefaultHomepage{
    return defaultHP;
}

@end

Thanks for the help in advance.

--Alan



____________________________________________________
Start your day with Yahoo! - make it your home page
http://www.yahoo.com/r/hs

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: Vu-meter
  • Next by Date: sub-ranges for NSLink attribute
  • Previous by thread: Re: range from link
  • Next by thread: sub-ranges for NSLink attribute
  • Index(es):
    • Date
    • Thread