contenteditable not working in safari but works in chrome

坚强是说给别人听的谎言 提交于 2020-01-02 00:57:12

问题


I'm having a strange issue...

This works in chrome as expected but in safari it only gets .. glowing but doesn't react on key input..

this is the method that fires the text edition:

var namebloc = $(event.currentTarget).find('.column_filename');
var oldvalue = namebloc.html();

namebloc.attr('contentEditable', true).focus();
document.execCommand('selectAll',false,null);

namebloc.blur(function() 
    {
    $(this).attr('contentEditable', false).unbind( "keydown" ).unbind( "blur" );
    var newvalue = $(this).html().replace('"','&quot;').replace(/(<([^>]+)>)/ig,"");
    console.log(newvalue);
    });
namebloc.keydown(function(e)
    {
    if(e.keyCode==27){ $(this).html(oldvalue);}//escape
    if(e.keyCode==13){  $(this).blur(); }//enter    
    });

This is a screenshot in chrome when fired this works as expected...

and this is the result in safari.. no reaction to keyboard or mouse selection:

Any idea why and how to solve this in safari?

this is the HTML before the method is called :

<span field="filename" class="column_filename" style="width:763px;">eiffel (2).JPG</span>

This is when it's called (at the same time as screenshots)

<span field="filename" class="column_filename" style="width:763px;" contenteditable="true">eiffel (2).JPG</span>

回答1:


Safari has the user-select CSS setting as none by default. You can use:

[contenteditable] {
    -webkit-user-select: text;
    user-select: text;
}

To make it work.



来源:https://stackoverflow.com/questions/20435166/contenteditable-not-working-in-safari-but-works-in-chrome

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!