JavaScript.xml 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="JavaScript" inherits="Object" version="3.4">
  3. <brief_description>
  4. Singleton that connects the engine with the browser's JavaScript context in HTML5 export.
  5. </brief_description>
  6. <description>
  7. The JavaScript singleton is implemented only in the HTML5 export. It's used to access the browser's JavaScript context. This allows interaction with embedding pages or calling third-party JavaScript APIs.
  8. [b]Note:[/b] This singleton can be disabled at build-time to improve security. By default, the JavaScript singleton is enabled. Official export templates also have the JavaScript singleton enabled. See [url=https://docs.godotengine.org/en/3.3/development/compiling/compiling_for_web.html]Compiling for the Web[/url] in the documentation for more information.
  9. </description>
  10. <tutorials>
  11. <link>https://docs.godotengine.org/en/3.3/getting_started/workflow/export/exporting_for_web.html#calling-javascript-from-script</link>
  12. </tutorials>
  13. <methods>
  14. <method name="create_callback">
  15. <return type="JavaScriptObject">
  16. </return>
  17. <argument index="0" name="object" type="Object">
  18. </argument>
  19. <argument index="1" name="method" type="String">
  20. </argument>
  21. <description>
  22. Creates a reference to a script function that can be used as a callback by JavaScript. The reference must be kept until the callback happens, or it won't be called at all. See [JavaScriptObject] for usage.
  23. </description>
  24. </method>
  25. <method name="create_object" qualifiers="vararg">
  26. <return type="Variant">
  27. </return>
  28. <argument index="0" name="object" type="String">
  29. </argument>
  30. <description>
  31. Creates a new JavaScript object using the [code]new[/code] constructor. The [code]object[/code] must a valid property of the JavaScript [code]window[/code]. See [JavaScriptObject] for usage.
  32. </description>
  33. </method>
  34. <method name="download_buffer">
  35. <return type="void">
  36. </return>
  37. <argument index="0" name="buffer" type="PoolByteArray">
  38. </argument>
  39. <argument index="1" name="name" type="String">
  40. </argument>
  41. <argument index="2" name="mime" type="String" default="&quot;application/octet-stream&quot;">
  42. </argument>
  43. <description>
  44. Prompts the user to download a file containing the specified [code]buffer[/code]. The file will have the given [code]name[/code] and [code]mime[/code] type.
  45. [b]Note:[/b] The browser may override the [url=https://en.wikipedia.org/wiki/Media_type]MIME type[/url] provided based on the file [code]name[/code]'s extension.
  46. [b]Note:[/b] Browsers might block the download if [method download_buffer] is not being called from a user interaction (e.g. button click).
  47. [b]Note:[/b] Browsers might ask the user for permission or block the download if multiple download requests are made in a quick succession.
  48. </description>
  49. </method>
  50. <method name="eval">
  51. <return type="Variant">
  52. </return>
  53. <argument index="0" name="code" type="String">
  54. </argument>
  55. <argument index="1" name="use_global_execution_context" type="bool" default="false">
  56. </argument>
  57. <description>
  58. Execute the string [code]code[/code] as JavaScript code within the browser window. This is a call to the actual global JavaScript function [code]eval()[/code].
  59. If [code]use_global_execution_context[/code] is [code]true[/code], the code will be evaluated in the global execution context. Otherwise, it is evaluated in the execution context of a function within the engine's runtime environment.
  60. </description>
  61. </method>
  62. <method name="get_interface">
  63. <return type="JavaScriptObject">
  64. </return>
  65. <argument index="0" name="interface" type="String">
  66. </argument>
  67. <description>
  68. Returns an interface to a JavaScript object that can be used by scripts. The [code]interface[/code] must be a valid property of the JavaScript [code]window[/code]. The callback must accept a single [Array] argument, which will contain the JavaScript [code]arguments[/code]. See [JavaScriptObject] for usage.
  69. </description>
  70. </method>
  71. </methods>
  72. <constants>
  73. </constants>
  74. </class>