整个页面弹出消息,与警报

时间:2016-07-01 07:47:47

标签: 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>

任何帮助将不胜感激!

2 个答案:

答案 0 :(得分:0)

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

configurations.compile.files.each {
   println it
}

答案 1 :(得分:0)

我认为您无法使用href在锚标记上trigger click

您可以使用window.location.href

if(isChrome){
  var href = $('#thebutton').attr('href');
      window.location.href = href; 
    //alert("Chrome is detected");

}

JSFIDDLE

相关问题