Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9180129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:58:12+00:00 2026-06-17T17:58:12+00:00

I am trying to get a ‘windowScriptObject’ working, this is my Objective-C code below:

  • 0

I am trying to get a ‘windowScriptObject’ working, this is my Objective-C code below:

- (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');"]; 
}

The above code works when I inject JavaScript (evaluateWebScript)

This sis what the console out put is:

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: <WidgetsDelegate: 0x10133de60>
2012-12-06 08:03:05.607 BetterDesktop[8669:303] JSLog: Test

The command works, however when I use a page it doesn’t work.

<html>
<head>
<script type="text/javascript">
if (typeof(MyApp) != "undefined"){
document.write('<br/><h1>hi</h1>');
MyApp.consoleLog_('Test from HTML');
}
else{

document.write('<br/><h1>Not Defined</h1>');
}

</script>
</head>
<body>
</body>
</html>

It believes that ‘MyApp’ is undefined, any suggestions?

(By the way, the WebView is not connected to this class, it is just the delegate)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T17:58:14+00:00Added an answer on June 17, 2026 at 5:58 pm

    You should inject your objects in to the WebView from within the -webView:didClearWindowObject:forFrame: WebFrameLoadDelegate method rather than within -webView:didFinishLoadForFrame:. The window object is not guaranteed to have been correctly initialized until didClearWindowObject is called.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying get some licensing code from AndroidPit.com working, but I get Unable to
below is my code through which I'm trying get certain values to a drop
I am trying get this ListView working and i'm trying to sort the list
I'm trying get the code below to always highlight the current page of a
I've this code that uses Savon that I'm trying get to work. require savon
Trying to get this expression to work, can someone look at it and tell
I am trying get the values using SP.The query is below. create proc [dbo].[GetOrdersByUserID11]
I am trying get the html within .event_recur. $(.entry).each(function(){ alert($(this).find(.event_recur).html()); }); <div class=entry> <p
When I'm trying get method from remote webservice it gives me error. My code
I'm trying get cross compiling between 2.7.7 and 2.8.0. The package is included, this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.