在我的应用程序中,它不应允许用户在同一浏览器的多个选项卡中打开应用程序。出于某种安全目的,我需要实现此目的。我如何在 Angular 8 中实现这个?
带有 localStorage 和 Storage 监听器的较短版本
<script type="text/javascript">
// Broadcast that you're opening a page.
localStorage.openpages = Date.now();
var onLocalStorageEvent = function(e){
if(e.key == "openpages"){
// Listen if anybody else is opening the same page!
localStorage.page_available = Date.now();
}
if(e.key == "page_available"){
alert("One more page already open");
}
};
window.addEventListener('storage', onLocalStorageEvent, false);
</script>
我没有足够的声誉来支持答案,但该解决方案对我有用。谢谢你。