title: Objective-C/Cocoa windowScriptObject commands not working from loaded page
body: <p>I am trying to get a 'windowScriptObject' working, this is my Objective-C code below:</p>
  
  <pre><code>- (void)consoleLog:(NSString *)aMessage {
      NSLog(@"JSLog: %@", aMessage); }
  
  + (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector {
      if (aSelector == @selector(consoleLog:)) {
          return NO;
      }
  
      return YES; }
  
  - (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame {
  
      NSLog(@"Did finnish load...");
      scriptObject = [sender windowScriptObject];
  
      //obviously, this returns undefined
      NSLog(@"Object: %@",[scriptObject evaluateWebScript:@"MyApp"]);
  
      //set the value of MyApp
      [scriptObject setValue:self forKey:@"MyApp"];
  
      //this now returns the value
      NSLog(@"Object: %@",[scriptObject evaluateWebScript:@"MyApp"]);
  
  
  
  
      //this command now works from here
      [scriptObject evaluateWebScript:@"MyApp.consoleLog_('Test');"]; 
  }
  </code></pre>
  
  <p>The above code works when I inject JavaScript (<em>evaluateWebScript</em>)</p>
  
  <p>This sis what the console out put is:</p>
  
  <pre><code>2012-12-06 08:03:05.605 BetterDesktop[8669:303] Did finnish load...
  2012-12-06 08:03:05.605 BetterDesktop[8669:303] Object: undefined
  2012-12-06 08:03:05.606 BetterDesktop[8669:303] Object: &lt;WidgetsDelegate: 0x10133de60&gt;
  2012-12-06 08:03:05.607 BetterDesktop[8669:303] JSLog: Test
  </code></pre>
  
  <p>The command works, however when I use a page it doesn't work.</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;script type="text/javascript"&gt;
  if (typeof(MyApp) != "undefined"){
  document.write('&lt;br/&gt;&lt;h1&gt;hi&lt;/h1&gt;');
  MyApp.consoleLog_('Test from HTML');
  }
  else{
  
  document.write('&lt;br/&gt;&lt;h1&gt;Not Defined&lt;/h1&gt;');
  }
  
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>It believes that 'MyApp' is undefined, any suggestions?</p>
  
  <p>(By the way, the WebView is not connected to this class, it is just the delegate)</p>