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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
