我想知道如何在加载时弹出一个css样式框,告诉您正在使用的浏览器。我有浏览器识别码,但我不知道如何在加载时显示弹出窗口。 Popup就是我的全部:
$(document).ready(function() {});
浏览器检测:
function myFunction() { if((navigator.userAgent.indexOf("Opera") || navigator.userAgent.indexOf('OPR')) != -1 ) { alert('Opera'); } else if(navigator.userAgent.indexOf("Chrome") != -1 ) { alert('Chrome'); } else if(navigator.userAgent.indexOf("Safari") != -1) { alert('Safari'); } else if(navigator.userAgent.indexOf("Firefox") != -1 ) { alert('Firefox'); } else if((navigator.userAgent.indexOf("MSIE") != -1 ) || (!!document.documentMode == true )) //IF IE > 10 { alert('IE'); } else { alert('unknown'); } }
答案 0 :(得分:1)
我的建议是,不使用jQuery ui对话框并仅使用css来构建弹出窗口:
function myFunction() {
if ((navigator.userAgent.indexOf("Opera") || navigator.userAgent.indexOf('OPR')) != -1) {
return'Opera';
} else if (navigator.userAgent.indexOf("Chrome") != -1) {
return 'Chrome';
} else if (navigator.userAgent.indexOf("Safari") != -1) {
return 'Safari';
} else if (navigator.userAgent.indexOf("Firefox") != -1) {
return 'Firefox';
} else if ((navigator.userAgent.indexOf("MSIE") != -1 ) || (!!document.documentMode == true )) { //IF IE > 10
return 'IE';
}
return 'unknown';
}
function popupClose() {
$('#popup').hide();
}
$(function () {
$('.content').text(myFunction());
});
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
visibility: visible;
}
.overlay:target {
visibility: visible;
opacity: 1;
}
.popup {
margin: 70px auto;
padding: 20px;
background:slategray;
border-radius: 5px;
width: 30%;
position: relative;
transition: all 5s ease-in-out;
}
.popup h2 {
margin-top: 0;
color: #333;
font-family: Tahoma, Arial, sans-serif;
text-align: center;
}
.popup .close {
position: absolute;
top: 20px;
right: 30px;
transition: all 200ms;
font-size: 30px;
font-weight: bold;
text-decoration: none;
color: #333;
}
.popup .close:hover {
color: #06D85F;
}
.popup .content {
max-height: 30%;
overflow: auto;
text-align: center;
}
@media screen and (max-width: 700px){
.box{
width: 70%;
}
.popup{
width: 70%;
}
}
<script src="http://code.jquery.com/jquery-1.11.3.js"></script>
<div id="popup" class="overlay">
<div class="popup">
<h2>Browser</h2>
<a class="close" href="javascript:popupClose();">×</a>
<div class="content">
</div>
</div>
</div>
答案 1 :(得分:0)
我的弹出功能来自: https://jsfiddle.net/mm7b7t5t/
(支持可拖动弹出窗口,多个按钮,表单,返回点击按钮等)
使用以下代码:
var browserPopup = new popup([{text: "Close"}], "Browser", "<p>"+browserName()+"</p>");
browserPopup.open();
function browserName() {
if ((navigator.userAgent.indexOf("Opera") || navigator.userAgent.indexOf('OPR')) != -1) {
return'Opera';
} else if (navigator.userAgent.indexOf("Chrome") != -1) {
return 'Chrome';
} else if (navigator.userAgent.indexOf("Safari") != -1) {
return 'Safari';
} else if (navigator.userAgent.indexOf("Firefox") != -1) {
return 'Firefox';
} else if ((navigator.userAgent.indexOf("MSIE") != -1 ) || (!!document.documentMode == true )) { //IF IE > 10
return 'IE';
}
return 'unknown';
}