You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by GitBox <gi...@apache.org> on 2022/09/28 13:02:20 UTC
[GitHub] [cordova-ios] breautek commented on issue #1263: When I inject js in iOS, there will be some errors, how should I inject custom js?
breautek commented on issue #1263:
URL: https://github.com/apache/cordova-ios/issues/1263#issuecomment-1260878594
> When I inject js in iOS, there will be some errors, how should I inject custom js?
You should load up JS using traditional means, such as a `<script>` tag.
Alternatively, you can use the standard [Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) constructor, which will create a function with the scope of the global object, but this isn't the recommended approach due to similar issues (although less severe) to the standard [eval](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval) function. [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval#never_use_eval!) writes about the bad practices behind both `eval` and the `Function` constructor.
If you're authoring a Cordova plugin, then refer to the [iOS plugin documentation](https://cordova.apache.org/docs/en/11.x/guide/platforms/ios/plugin.html). It contains [examples](https://cordova.apache.org/docs/en/11.x/guide/platforms/ios/plugin.html#echo-ios-plugin-example) of how to do cross communication between the native and javascript environments. Generally speaking, the application should respond to data with an appropriate, predefined function instead relying on the `eval` solution, which will likely introduce a security risk into your app.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org