jeudi 19 février 2015

execCommand('createLink') doesn't work in Firefox


I highlight the text and click on the <div class="link"></div>, typing link url into the textfield and press enter, but link doesn't creating in firefox ( in Chrome / Safari it works fine ).


create events:



events:{
'click .link': 'toggleLink',
'keypress [name="link"]': 'setUrl'
},


functions:



toggleLink: function(e){
if(this.options.nodes.url){
this.$el.find('[name="link"]').val(this.options.nodes.url);
}

this.lastRange = window.getSelection().getRangeAt(0);
this.$el.find('[name="link"]').focus();
},

setUrl: function(e){
if(e.which == 13){
e.preventDefault();
this.$el.find('[name="link"]').blur();
window.getSelection().addRange(this.lastRange);
var url = $(e.currentTarget).val();
if(url.length > 0){
document.execCommand('createLink', false, url);
}else{
document.execCommand('unlink', false, null);
}
}
}


What i'm doing wrong and why firefox don't want to create link? thx!





Aucun commentaire:

Enregistrer un commentaire