M
M
Max Pavlyukevich2015-02-20 11:31:53
JavaScript
Max Pavlyukevich, 2015-02-20 11:31:53

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

Good afternoon! I ask for help.

When I select the text, a toolbar appears above it with the "create link" button, by clicking on this button, input appears and the cursor immediately focuses on this input, I enter the link, press enter, and nothing happens in firefox (the link is not created), in chrome and safari all work fine, what could be the reason?

create events:

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


the functions of the events themselves:

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 am I doing wrong and why does firefox not want to understand that I have entered a link? thank!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Kitmanov, 2015-02-21
@k12th

And what exactly is the problem - does the handler (setUrl method) not start, or is something wrong already happening in it?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question