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 7932821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:08:02+00:00 2026-06-03T21:08:02+00:00

I´m new to PhoneGap/CoffeeScript trying to get a Hello World App running in iOS

  • 0

I´m new to PhoneGap/CoffeeScript trying to get a Hello World App running in iOS and wonder what I´m doing wrong.

This would be my standard index.html:

<!DOCTYPE html>
<html>
  <head>
  <title></title>

    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no;" />
  <meta charset="utf-8">


  <script type="text/javascript" charset="utf-8" src="cordova-1.6.0.js"></script>
  <script type="text/javascript" charset="utf-8" src="app.js"></script>

  </head>
  <body onload="onBodyLoad()">
  <h1>Hey, it's Cordova!</h1>
  <p>Don't know how to get started? Check out our <em><a target="_blank" href="http://docs.phonegap.com/en/edge/guide_getting-started_ios_index.md.html#Getting%20Started%20with%20iOS">Getting Started Guide</a></em>

  </body>
</html>

And the app.js generated from app.coffee looks like this:

(function() {
    var onBodyLoad, onDeviceReady;

    onBodyLoad = function() {
        return document.addEventListener("deviceready", onDeviceReady, false);
    };

    onDeviceReady = function() {
        return navigator.notification.alert("This alert never happens!");
    };

}).call(this);

When I delete the first line “(function() {” and the last line “}).call(this);” of the app.js get the alert and everything is working properly.
But I guess there´s a better way than deleting this lines everytime CoffeeScript compiles into JavaScript.

thank you very much,
Jakob

  • 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-03T21:08:03+00:00Added an answer on June 3, 2026 at 9:08 pm

    Coffeescript wraps each file in a function to prevent it from polluting the global namespace. If you really want to do it this way, you could change the declaration of onBodyLoad to window.onBodyLoad, but best practices explicitly oppose placing Javascript calls in HTML elements like onload.

    This is a variation on a popular question. Here is an example of how you can use an event listener to unobtrusively have your function called when the page has loaded.

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

Sidebar

Related Questions

I have an app made using jquerymobile+phonegap, and running under iOS. The surpise arrived
on my attempt to build a PhoneGap-based iOS app, I stumbled upon this problem.
I am new to phonegap. I am using phonegap with IOS. the problem i
I am building a phonegap app for iOS which works perfectly and beautifully except
I'm new to phoneGap, and i'm trying to implement a webview in android with
I am creating a new app using phonegap (html and javascript) and am using
I am completelly new to PhoneGap (not to iOS programming) and I have from
I am new to Windows Phone (using PhoneGap). Where does the created file get
I'm new to Blackberry. I use phonegap to create cross platform applications. I'm trying
I'm new to mobile web development, and I just made a mobile-app with PhoneGap,

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.