简体   繁体   English

React-Native:在运行时在webview中动态注入javascript

[英]React-Native: Injecting javascript dynamically in webview on runtime

I am currently working on a project where I need to load the user in a webview, in the same time I'm injecting a javascript code to check if tokens expired. 我目前正在开发一个项目,我需要在webview中加载用户,同时我正在注入一个javascript代码来检查令牌是否已过期。 Everything works till here, I am getting a message back from the webview that we need to refresh but I cannot figure out how I can inject javascript on runtime in the webview. 一切都在这里工作,我从webview得到一条消息,我们需要刷新,但我无法弄清楚如何在webview中在运行时注入javascript。 I am using at the moment this module: https://github.com/alinz/react-native-webview-bridge . 我目前正在使用这个模块: https//github.com/alinz/react-native-webview-bridge

Is there a way how to make this flow working? 有没有办法让这个流程工作? So like this the tokens will not expire if the user is using the application. 因此,如果用户正在使用该应用程序,则令牌将不会过期。

Can't you just insert a new script element into the page's body? 你不能只是在页面的主体中插入一个新的脚本元素吗?

Perhaps something like the answer to this question: Adding <script> element to the DOM and have the javascript run? 也许就像这个问题的答案: 将<script>元素添加到DOM并运行javascript?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM