Javascript 如何使脚本标记适应角度?

Javascript 如何使脚本标记适应角度?,javascript,angular,Javascript,Angular,在我的旧网站上,我遇到了一些坏人的问题,他们试图克隆我的网站。 现在我尝试将应用程序传递给Angular7 我在旧页面中实施的措施之一是,为了结束克隆尝试,使用.js代码从标题检查主机名。 <script type="text/javascript"> if(!['mysite.com','testsite.com'].includes(window.location.hostname)){ window.location.href = 'https://go

在我的旧网站上,我遇到了一些坏人的问题,他们试图克隆我的网站。 现在我尝试将应用程序传递给Angular7

我在旧页面中实施的措施之一是,为了结束克隆尝试,使用
.js
代码从标题检查主机名。

<script type="text/javascript">
if(!['mysite.com','testsite.com'].includes(window.location.hostname)){
            window.location.href = 'https://google.com'; 
}
</script>

如果(!['mysite.com','testsite.com'].includes(window.location.hostname)){
window.location.href=https://google.com'; 
}
有人能告诉我如何转换(重写、改编)这段Javascript代码以便在Angular中使用吗?

我想在源代码中使用这段代码(如果可能的话),这样它可以在运行后编译-
npm run build
,这样它就可以集成在我的网站的
main.js
中。

在你的index.html中

添加此代码

例子 src/app/index.html


栈溢出
如果(!['mysite.com','testsite.com'].includes(window.location.hostname)){
window.location.href=https://google.com'; 
}

好的,谢谢George,但我想在我的应用程序的源代码下添加此代码(如果可能的话),所以我需要集成到main.js中(在npm运行构建之后)-这是为了使跳转更困难,或者删除此代码,以防其他人尝试再次克隆我的应用程序site@ivan如果我帮了你,请投票表决我的答案。是的,你可以添加这个,你将在最后一个捆绑包中有这个。
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Stackoverflow</title>
  <base href="/">

  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
  <app-root></app-root>

  <script type="text/javascript">
  if(!['mysite.com','testsite.com'].includes(window.location.hostname)){
            window.location.href = 'https://google.com'; 
  }
</script>
</body>
</html>