Change theme
Help
Press space for more information.
Show links for this issue (Shortcut: i, l)
Copy issue ID
Previous Issue (Shortcut: k)
Next Issue (Shortcut: j)
Sign in to use full features.
Vote: I am impacted
Notification menu
Refresh (Shortcut: Shift+r)
Go home (Shortcut: u)
Pending code changes (auto-populated)
Needs more info comment that > 10 days [ID: 963198]
Comment such as: SPAM, non-actionable [ID: 963127]
Resolved actionable follow-up comments [ID: 963027]
View issue level access limits(Press Alt + Right arrow for more information)
Attachment actions
Unintended behavior
View staffing
Description
If the same function is called without parentheses (e.g. "window.onload=function;"), the page loading will complete as expected.
Sample code attached (based on the official demo code at
- a 4-line PHP file which includes a JS file
- a JS file with the API init function.
To reproduce the bug, on the last line of the PHP file change "initialize" to "initialize()".
There are cases when the init function cannot be called in the "<body>" tag (like the official tutorial suggests) because it is unavailable (e.g., a plugin in a CMS wants to draw a map). In this case calling it in "window.onload" seems proper approach.
Also, there are cases where parentheses are mandatory, e.g. when an argument needs to be passed (like a path to a KML file which should be loaded in an overlay). In this case the following workaround has been adopted:
- use global variables
- set them in a separate function which is also called on "window.onload", but before the API init funtion.
- make the API init function use the global variable.