简体   繁体   English

回传不适用于Safari中的鼠标单击

[英]Postback not working on mouse click in Safari

So I have a dropdown context box, which I use to select which item I am going to be working with. 因此,我有一个下拉上下文框,用于选择要使用的项目。

Now everything seems to be working on all browsers except Safari. 现在,一切似乎都可以在除Safari之外的所有浏览器上运行。 I have a type function that works fine in safari if you focus on the box and type the name in and hit enter. 我有一个类型功能,如果您专注于该框并在其中输入名称并按Enter,则可以在野生动物园中正常工作。 However my issue is with the mouse click. 但是我的问题是鼠标单击。 If I select an item from the dropdown and click it, the postback doesn't work until I hit enter on the keyboard. 如果我从下拉菜单中选择一项,然后单击它,则在按键盘上的Enter键之前,回发不起作用。

Here is my .ascx.cs file 这是我的.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();");
        }
    }

Here is the typeAhead() function 这是typeAhead()函数

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);
        }
....

Now I have a section in the typeAhead for the chrome browser, but everything I try for safari doesn't seem to allow me to use the mouse click to select an item. 现在,我在chrome浏览器的typeAhead中有一个部分,但我尝试进行野生动物园的所有操作似乎都不允许我使用鼠标单击来选择项。

Any help would be appreciated. 任何帮助,将不胜感激。

simple fix. 简单修复。 safari recognizes onchange so once I added that, it worked fine. Safari可以识别onchange因此一旦我添加了它,它就可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM