React Native:如何在组件中添加脚本标签 [英] React Native: How to add script tag in the component

查看:53
本文介绍了React Native:如何在组件中添加脚本标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 React Native 应用程序的组件内添加标签.下面是我的代码,它似乎不起作用.谁能告诉我如何解决这个问题?

I am trying to add tag inside the component for the React Native app. Below is my code and it doesn't seem to work. Could anyone please tell me how to solve this issue?

import React, {Component} from 'react';
import PropTypes from 'prop-types';
import Dimensions from 'Dimensions';
import {StyleSheet, View, TextInput, Image, Text} from 'react-native';

export default class Chatbot extends Component {
  render() {
    return (
      <View>
        <Text>Testing</Text>
        
		<script type="text/javascript">
		    window.__be = window.__be || {};
		    window.__be.id = "5b3a47b4b30a36000769d821";
		    (function() {
		        var be = document.createElement('script'); be.type = 'text/javascript'; be.async = true;
		        be.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'cdn.botengine.ai/widget/plugin.js';
		        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(be, s);
		    })();
		</script>

      </View>
    );
  }
}

推荐答案

我猜你写的代码不会在浏览器中运行.脚本标签用于告诉浏览器:嘿浏览器,停止.我们这里有一些 javascript.执行它",所以你应该忘记脚本标签.

My guess is that the code you are writing will not run in a browser. The script tag serves to tell the BROWSER: "Hey browser, stop. We got some javascript here. Execute it", so you should forget about the script tag.

这篇关于React Native:如何在组件中添加脚本标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆