Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Opening new browser window

Opening new browser window
Thread Tools
Mac Enthusiast
Join Date: Mar 2003
Location: Atlanta, GA
Status: Offline
Reply With Quote
Feb 26, 2004, 10:57 AM
 
I am messing around with WebViews, and right now, I am trying to set it up to open new windows when that request is made. My code looks like this:
Code:
- (WebView *)webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request { id newWindow = [[NSDocumentController sharedDocumentController] openUntitledDocumentOfType:@"DocumentType" display:YES]; [[[newWindow webView] mainFrame] loadRequest:request]; return [newWindow webView]; } - (void)webViewShow:(WebView *)sender { id newWindow = [[NSDocumentController sharedDocumentController] documentForWindow:[sender window]]; [newWindow showWindows]; }
When I run the program, and choose to open a link in a new window, a new window opens, but it just goes to the set homepage. The "run" window gives me the following errors:

2004-02-26 11:53:02.590 Web Browser[562] *** -[MyDocument webView]: selector not recognized
2004-02-26 11:53:02.599 Web Browser[562] *** -[MyDocument webView]: selector not recognized


Does anyone know what could be wrong?
     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Feb 26, 2004, 01:21 PM
 
Code:
id newWindow = [[NSDocumentController sharedDocumentController] openUntitledDocumentOfType:@"DocumentType" display:YES];
This doesn't actually create a window, it creates an NSDocument subclass. In your case, it's creating an instance of MyDocument.
Code:
[[[newWindow webView] mainFrame] loadRequest:request];
[newWindow webView] doesn't mean anything because you apparently haven't implemented -[MyDocument webView].
     
Mac Enthusiast
Join Date: Mar 2003
Location: Atlanta, GA
Status: Offline
Reply With Quote
Feb 26, 2004, 01:38 PM
 
Thanks for the reply, but I'm still confused. I used the steps I found on ADC.
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Feb 26, 2004, 02:53 PM
 
Did you set up a webView outlet in MyDocument.h?
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Mac Enthusiast
Join Date: Mar 2003
Location: Atlanta, GA
Status: Offline
Reply With Quote
Feb 26, 2004, 03:16 PM
 
Originally posted by Chuckit:
Did you set up a webView outlet in MyDocument.h?
Yeah. I've already got the basics of the browser done (back/forward/reload/stop/address/search), and they are all using the webView outlet.
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Feb 26, 2004, 04:32 PM
 
Originally posted by hyperb0le:
Yeah. I've already got the basics of the browser done (back/forward/reload/stop/address/search), and they are all using the webView outlet.
I think they it's meant somewhere between the lines that you're supposed to set up a webView method to access the WebView.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Mac Enthusiast
Join Date: Mar 2003
Location: Atlanta, GA
Status: Offline
Reply With Quote
Mar 2, 2004, 09:46 PM
 
Originally posted by Chuckit:
I think they it's meant somewhere between the lines that you're supposed to set up a webView method to access the WebView.
I don't understand. Sorry, I'm new to this. Could you show me a sample?
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Mar 2, 2004, 10:49 PM
 
Originally posted by hyperb0le:
I don't understand. Sorry, I'm new to this. Could you show me a sample?
Just add to the following code to your class:
Code:
- (id)webView { return webView; }
That way, when you call [newWindow webView], it will return the proper object.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Mac Enthusiast
Join Date: Mar 2003
Location: Atlanta, GA
Status: Offline
Reply With Quote
Mar 2, 2004, 10:54 PM
 
Originally posted by Chuckit:
Just add to the following code to your class:
Code:
- (id)webView { return webView; }
That way, when you call [newWindow webView], it will return the proper object.
Perfect!! Thank you. I knew it had to be something simple like that.

Only problem now is that when I open a new window, the toolbars are identical for both windows. (They show the disabled/enabled state of the frontmost window. ie: If the front window can go back but the backmost can't, both windows show an enabled back button).
     
Mac Enthusiast
Join Date: Mar 2003
Location: Atlanta, GA
Status: Offline
Reply With Quote
Mar 5, 2004, 04:57 PM
 
Originally posted by hyperb0le:
Only problem now is that when I open a new window, the toolbars are identical for both windows. (They show the disabled/enabled state of the frontmost window. ie: If the front window can go back but the backmost can't, both windows show an enabled back button).
*BUMP* Anybody have an idea why this is happening?
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Mar 5, 2004, 05:23 PM
 
How are you validating your back/forward buttons? It sounds to me like you're somehow messaging the first responder rather than the WebView (or whatever WebKit item handles this) for the appropriate window.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Mac Enthusiast
Join Date: Mar 2003
Location: Atlanta, GA
Status: Offline
Reply With Quote
Mar 5, 2004, 09:59 PM
 
My code is the following for validating the back/forward buttons:

-(BOOL)validateToolbarItemNSToolbarItem*)toolbarI tem
{
if ([[toolbarItem itemIdentifier] isEqual:BackToolbarItemIdentifier]){
if ([webView canGoBack] == YES) {
enable = YES;
}
else
{
enable = NO;
}
}

else if ([[toolbarItem itemIdentifier] isEqual:ForwardToolbarItemIdentifier]){
if ([webView canGoForward] == YES) {
enable = YES;
}
else
{
enable = NO;
}
}
return enable;
}
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Mar 5, 2004, 11:15 PM
 
Where is this code located, and what is the target for the toolbar items? Like I said, it sounds like the first responder (which is generally in the key window) is being asked to validate rather than a specific object.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Mac Enthusiast
Join Date: Mar 2003
Location: Atlanta, GA
Status: Offline
Reply With Quote
Mar 6, 2004, 01:09 PM
 
The code i posted is located in MyDocument.h, and so is the toolbar creation code. The target for the back button is [webView goBack]; and the forward button targets [webView goForward];
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 08:57 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2