2011-04-09 4 views
0

나는 많은 주위를 검토 ​​한 결과, 나를 할 충분한 간단 아무것도 찾을 수가 없어 ... 실행 중이며 Firefox 4.0 이외의 항목 인 경우 Firefox 4.0 이상에서 페이지를 가장 잘 볼 수 있다는 경고를 표시하는 숨겨진 div가 표시됩니다. div 안에는 div onclick을 숨기는 버튼이 있습니다.jQuery를 쿠키 상담자 브라우저가 현재있는 감지하는 웹 페이지를 설정 한</p> <p>

나는이 단추가 세션 중에 클릭되어 사용자가 "집"페이지를 클릭 할 때마다 매번 같은 메시지를받지 않도록 기억하고 있습니다.

현재 코드 :

<head> 
    <script src="js/browsercheck.js"></script> 
    <script type="text/javascript"> 
     // external script "browsercheck.js" checks 
     // which browser/version is being used 
     // check browser and display message if != Firefox 4.0 or > 
     function checkBrowser() { 
      var browser = BrowserDetect.browser; 
      var version = BrowserDetect.version; 
      if (browser == "Firefox") { 
       if (version >= 4) { 
        // do nothing 
       } 
      } else { 
       document.getElementById("coverall").style.visibility="visible"; 
       document.getElementById("browser").innerHTML = browser + " " + version; 
      } 
     } 
     // remove overlay if user commands 
     function removeCoverall() { 
      document.getElementById("coverall").style.visibility="hidden"; 
     } 
    </script> 
</head> 
<body> 
    <div id="coverall" style="visibility:hidden;"> 
     <p>I see you're using <span id="browser"></span>. Please use Firefox.</p> 
     <button type="button" onclick="removeCoverall()">I understand</button> 
    </div> 
</body> 
+0

제목에 jQuery가 언급되어 있지만 jQuery를 전혀 사용하지 않습니다 ...이 질문은 jQuery와 어떤 관련이 있습니까? –

+0

jQuery를 전혀 사용하지 않는 것으로 보입니다. 하지만 실제로 있다면 jquery 쿠키 플러그인을 살펴보십시오 : http : //plugins.jquery.com/project/Cookie – Talljoe

답변

1

jQuery를하고 cookie plugin를 사용하여, 당신은 할 수 있습니다 :

 
function removeCoverall() { 
      $.cookie("user_clicked_ok", "true"); 
      document.getElementById("coverall").style.visibility="hidden"; 
     } 

$(window).ready(function() { 
    if ($.cookie("user_clicked_ok")=="true") {removeCoverall();} 
}); 

자세한 내용에 : http://www.electrictoolbox.com/jquery-cookies/

+0

그래야 작동하는 것처럼 보이지만 저는 JS/jQuery에 익숙합니다. 나는 단지 기초를 알고, 어떤 이유로 쿠키가 나를 혼란스럽게합니다. 구현 방법을 정확히 기재 하시겠습니까? 이 일을 할 수없는 것 같아. – JacobTheDev

0

을 나타냅니다 당신이 set a cookie 수 있었던 removeCoverall 함수에서 사용자가 div를 닫은 후 checkBrowser 함수가 표시 전에 쿠키가 있는지 확인합니다. div. ing.

0
You seem to have the right idea, you need cookies! YUM! 

JS

function removeCoverall() { 
    var date = new Date(); 
    date.setTime(date.getTime()+(7*24*60*60*1000));// expires in one week 
    document.cookie = 'skipNotify=1;expires='+date.toGMTString()+'; path=/'; 
    document.getElementById("coverall").style.visibility="hidden"; 
} 

이제 자바 스크립트가 어려울 수 있습니다 쿠키를 검색하지만 PHP를 사용할 수 있습니다!

PHP

function checkBrowser() { 
    <?php if(isset($_COOKIE['skipNotify']))echo'return;';?> 
    var browser = BrowserDetect.browser; 
    var version = BrowserDetect.version; 
    if (browser == "Firefox") { 
     if (version >= 4) { 
      // do nothing 
     } 
    } else { 
     document.getElementById("coverall").style.visibility="visible"; 
     document.getElementById("browser").innerHTML = browser + " " + version; 
    } 
} 

사용자가 쿠키를 경우 위의 코드는 return 문을 주입하기 때문에 함수 호출이 아무것도하지 않습니다.

다른 게시물에서 언급했듯이 모든 자바 스크립트 요구 사항에 jQuery을 사용하는 것이 좋습니다. 매우 인기 있고 안정적이며 유용합니다! 제 3 자 솔루션을 사용하지 않기 때문에 답을 준 것뿐입니다.