javascript - 整页弹出消息配合alert激活

标签 javascript jquery html css

我有一个网站,它能够成功检测您是否使用 Chrome 作为浏览器,并且运行良好。

这个“元素”的编码是 -

var isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
if(isChrome){
    alert("Chrome is detected");
}

另一个元素是透明的整个页面弹出消息。这在使用 HTML 按钮激活消息时也能完美工作。但是我需要在 Javascript 中激活弹出窗口,而不是在单击按钮时激活弹出窗口,我希望在上面的 alert("Chrome is detected"); 行中激活它。这个元素的编码在下面,你会明白我的意思......

<!DOCTYPE html> 
<head>
<style> 
.button{ width: 150px; padding: 10px; background-color: #FF8C00; box-shadow: -8px 8px 10px 3px rgba(0,0,0,0.2); font-weight:bold; text-decoration:none;
} 
#cover{ position:fixed; top:0; left:0; background:rgba(0,0,0,0.6); z-index:5; width:100%; height:100%; display:none;
} 
#loginScreen{ height:380px; width:340px; margin:0 auto; position:relative; z-index:10; display:none; background-color: white; no-repeat; border:5px solid #cccccc; border-radius:10px;
} 
#loginScreen:target, #loginScreen:target + #cover{ display:block; opacity:2;
}
.cancel{ display:block; position:absolute; top:3px; right:2px; background:rgb(245,245,245); color:black; height:32px; width:32px; font-size:30px; text-decoration:none; text-align:center; font-weight:bold; border-radius:36px;
} 
</style> 
</head> 
<body> 
<div id="top" align="center">

<!-- PLEASE DIRECT YOUR ATTENTION TO THE LINE BELOW -->
<a href="#loginScreen" class="button" id="thebutton">Click here to Log In</a> <!-- THIS IS HOW THE POP UP IS ACTIVATED BUT I NEED TO ACHIEVE THIS LINE IN JAVASCRIPT -->

</div>
<div id="loginScreen"> 
<span style="font-size:30px">Attention User!</span>
<a href="#" class="cancel" id="exitbutton">&times;</a>
</div>
<div id="cover" ></div>
</body>
</html>

如有任何帮助,我们将不胜感激!

最佳答案

如果您想在检测到 func 为真时打开弹出窗口,请像这样更改您的代码:

if(isChrome){
     // alert("Chrome is detected");
     $("#exitbutton").trigger('click'); //
}

关于javascript - 整页弹出消息配合alert激活,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38139866/

相关文章:

javascript - 如何为 HTML 表格设置固定行数?

javascript - Vue、js 组件计算属性中对 DOM 元素的引用

javascript - 我想在向下滚动时显示背景

javascript - jQuery 根据下拉列表中的选择更新 div

javascript - 单击按钮滚动到特定的 div

javascript - 通过单击所选的 div 来填充输入

html - 动态 HTML/CSS 按钮

javascript - 如何保护仅从前端使用的 API(Ajax 调用)

javascript - JS Bluebird Promise错误未提供任何细节

javascript - js : trigger function after a bunch of events were called