2016-07-01 2 views
0

브라우저를 Chrome으로 사용하고 있는지 완벽하게 감지 할 수있는 웹 사이트가 있는데 완벽하게 작동합니다.알림에 맞춰 전체 페이지 팝업 메시지가 표시됩니다.

이 "요소"에 대한 코딩은 -

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

다른 요소는 투명 페이지 전체가 메시지를 팝업입니다. 이것은 HTML 단추를 사용하여 메시지를 활성화 할 때도 완벽하게 작동합니다. 하지만 자바 스크립트에서 버튼 클릭이 아닌 활성화 될 팝업이 필요합니다. 활성화하려면 위의 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> 

도움이 될만한 정보가 있습니까? 이 경우는 true FUNC 감지 할 때 팝업을 열고 싶은 경우

+1

window.location.href 어떻게 질문에 제목을 관련이 사용할 수 있습니까? – Teemu

답변

0

, 다음과 같이 코드를 변경 :

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

죄송하지만 아무 것도하지 않습니다. PS : 도움이 필요하면 웹 사이트에서 Jquery를 사용하지 않습니다. 죄송합니다. – user5286985

+0

안녕하세요, 다음과 같이 사용할 수 있습니다. var el = document.getElementById ('# exitbutton'); el.onclick(); – mehmetakifalp

+0

하지만 .onclick(); 팝을 디파퍼로 만드시겠습니까? @mehmetakifalp – user5286985

0

을 내가 해달라고 생각 당신은 HREF와 앵커 태그의 수에 triggerclick.

당신은

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

} 

JSFIDDLE

+0

버튼을 제거했을 때 더 이상 모든 것이 작동하지 않게 되었기 때문에 – user5286985

+0

어쨌든 #loginScreen과 #cover의 디스플레이를 설정하는 버튼을 추가 할 수는 있었지만 시도해 보았습니다. 그러나 나는 다른 누군가가 그렇게 할 수있을 것이라고 생각한다. – user5286985

+0

** 나는 더 이상 그것을 원하지 않는다. ** 그러면 당신은 그것을 어떻게 트리거 할 것이고 어떤 요소에 href 속성을 추가하고 싶습니까? – brk

관련 문제