2012-10-18 3 views
2

그래서 내가 작업 할 항목을 선택하는 데 사용하는 드롭 다운 컨텍스트 상자가 있습니다.Safari에서 마우스를 클릭 할 때 포스트 백이 작동하지 않습니다.

이제 모든 것이 Safari를 제외한 모든 브라우저에서 작동하는 것 같습니다. 상자에 초점을 맞추고 이름을 입력하고 Enter 키를 누르면 사파리에서 올바르게 작동하는 유형 함수가 있습니다. 그러나 내 문제는 마우스 클릭입니다. 드롭 다운에서 항목을 선택하고 클릭하면 키보드에서 Enter 키를 누르기 전까지 포스트 백이 작동하지 않습니다. 여기

여기 내 .ascx.cs 파일

... 
if (cboContext.Visible) 
    { 
     string postBackFunction = "function contextPostback() {\n" 
     + "var newValue = document.getElementById(\"" + cboContext.ClientID + "\").value;\n" 
     + "if (newValue != " + cboContext.SelectedValue + ") " + Page.ClientScript.GetPostBackEventReference(cboContext, "") + ";\n}"; 

     Page.ClientScript.RegisterClientScriptBlock(typeof(string), "contextPostback", postBackFunction, true); 

     if (Request.UserAgent.ToLower().IndexOf("chrome") > -1) 
     { 
      cboContext.Attributes.Add("onkeypress", "if (typeAhead(event,'" + cboContext.ClientID + "') == 1) contextPostback();"); 
      cboContext.Attributes.Add("onclick", "contextPostback();"); 
     } 
     else if (Request.UserAgent.ToLower().IndexOf("safari") > -1) 
     { 
      cboContext.Attributes.Add("onclick", "contextPostback();"); 
      cboContext.Attributes.Add("onkeypress", "if (typeAhead(event,'" + cboContext.ClientID + "') == 1) contextPostback();"); 
      cboContext.Attributes.Add("onkeydown", "if (typeAhead(event,'" + cboContext.ClientID + "') == 1) contextPostback();"); 
      cboContext.Attributes.Add("onkeyup", "if (typeAhead(event,'" + cboContext.ClientID + "') == 1) contextPostback();"); 
     } 
     else 
     { 

      cboContext.Attributes.Add("onkeydown", "if (typeAhead(event,'" + cboContext.ClientID + "') == 1) contextPostback();"); 
      cboContext.Attributes.Add("onclick", "contextPostback();"); 
     } 
    } 

입니다

function typeAhead(e, nextFocus) { 

//don't trap Ctrl+keys 
if ((window.event && !window.event.ctrlKey) || (e && !e.ctrlKey)) { 

    // timer for current event 
    var now = new Date(); 

    .... 
    if (inputBuffer.accumString == "" || now - inputBuffer.last < inputBuffer.delay) { 
     //check for browsers 
     var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1; 
     var is_safari = navigator.userAgent.toLowerCase().indexOf('safari') > -1; 
     // make shortcut event object reference 
     var evt = e || window.event; 
     // get reference to the select element 
     var selectElem = evt.target || evt.srcElement; 
     // get typed character ASCII value 
     var charCode = evt.keyCode || evt.which; 
     // get the actual character, converted to uppercase 
     var newChar = ""; 
     // get reference to the actual form selection list 
     // added cross browser fix to enable the context switcher to work properly 
     if (is_chrome) { 
      var selection = document.getElementById("ctl00_ContextSwitch1_cboContext").selectedIndex; 
     } 
     else { 
      var selection = document.getElementById(nextFocus); 
     } 
.... 

가 지금은 크롬 브라우저의 선행 입력에 섹션을 가지고있는 선행 입력() 함수를하지만, 모든 나는 사파리 아무튼 노력 내가 마우스 클릭을 사용하여 항목을 선택할 수있는 것처럼 보입니다.

도움을 주시면 감사하겠습니다.

+0

onmouseup을 사용해 보셨나요? – danyim

+0

나는 onmouseup과 onmousedown을 시도했다. – TheLifeOfSteve

답변

1

간단한 수정. 사파리는 onchange을 인식하므로 일단 추가하면 제대로 작동합니다.

관련 문제