 |
 |
Opening new browser window
|
 |
|
 |
|
Mac Enthusiast
Join Date: Mar 2003
Location: Atlanta, GA
Status:
Offline
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
My code is the following for validating the back/forward buttons:
-(BOOL)validateToolbarItem  NSToolbarItem*)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
|
|
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
|
|
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];
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|