[英]How to adapt script tag to Angular?
在我的舊網站上,我遇到了一些壞人的問題,他們試圖克隆我的網站。 現在我嘗試將應用程序傳遞給 Angular7。
為了結束克隆嘗試,我在舊頁面中實施的措施之一是使用.js
代碼從標題中檢查主機名。
<script type="text/javascript">
if(!['mysite.com','testsite.com'].includes(window.location.hostname)){
window.location.href = 'https://google.com';
}
</script>
有人能告訴我如何轉換(重寫、改編)這段 Javascript 代碼,以便它可以在 Angular 中使用嗎?
我想在源代碼中使用這個代碼(如果可能的話),所以它可以在運行后編譯 - npm run build
- 以便它保持集成在我網站的main.js
中。
在你的 index.html
添加此代碼
源代碼/應用程序/index.html
<!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>
好的👍
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.