Opened 13 years ago

Last modified 7 years ago

#7145 confirmed New Feature

Allow opening links in edit mode

Reported by: Damian Owned by:
Priority: Normal Milestone:
Component: General Version: 3.0
Keywords: IBM Support Cc: Satya Minnekanti, James Cunningham, Teresa Monahan, mark@…

Description

When editing a document with links, CKEditor deliberately disables these links to allow proper editing of them. Some users would still like the ability to follow links in edit mode, as in Word.

This feature request proposes adding a keystroke, e.g. CTRL+click to allow the opening of a link target in a new window.

Change History (35)

comment:1 Changed 13 years ago by ComputecWebDev

Keywords: links edit mode click added; IBM removed

We would also appreciate this feature.

A custom hotfix would be to include this in your config-File (jQuery required):

CKEDITOR.on('instanceReady', function(ev) {						
	//catch ctrl+clicks on <a>'s in edit mode to open hrefs in new tab/window
	$('iframe').contents().click(function(e) {		
		if(typeof e.target.href != 'undefined' && e.ctrlKey == true) {			
			window.open(e.target.href, 'new' + e.screenX);
		}
	});	
});

Works with FF3.6.13 and most recent versions of Chrome/Opera/Safari (Windows). In IE8 however, CTRL+click selects one or more paragraphs, not sure where this comes from.

comment:2 Changed 13 years ago by Damian

Keywords: IBM added

Please do not remove the IBM keyword.

comment:3 Changed 13 years ago by Wiktor Walc

Keywords: links edit mode click removed
Status: newconfirmed
Version: 3.0

#6893 was marked as duplicate, a similar ticket for FCKeditor was mentioned there: http://dev.ckeditor.com/ticket/439 where we introduced two things: Ctrl + Click to follow the link and "Open Link" item in the context menu.

comment:4 Changed 13 years ago by Jakub Ś

Cc: satya,jamescun,tmonahansatya, jamescun, tmonahan

This issue was duplicated in #8251

comment:5 Changed 13 years ago by Jakub Ś

When editing a document with links, CKEditor deliberately disables these links to allow proper editing of them.

I don’t understand why blaming CKEditor? If you open a link inside document with body set to contenteditable="true", no link will be recognized be a browser. Only when using CRTL+right-click all browsers except IE will recognize it and display appropriate native context menu options.

In my opinion this is more about adding something extra to CKEditor to handle something which browsers can't.

As @wwalc and @duncansimey (in 8251) pointed out, in #439 such feature was introduced for FCK.

comment:6 in reply to:  5 ; Changed 13 years ago by Damian

Replying to j.swiderski:

I don’t understand why blaming CKEditor? If you open a link inside document with body set to contenteditable="true", no link will be recognized be a browser.

I wasn't blaming CKEditor, as I think it makes perfect sense to disable links in edit mode. Users would quickly become frustrated if they always activated the link by clicking it to edit it :)

Agreed, it is true that browsers disable links in contenteditable containers, but they don't disable CTRL+Click. CKEditor deliberately disables the click (and ctrl+click) event on anchors, see [5751].

In my opinion this is more about adding something extra to CKEditor to handle something which browsers can't.

Right, we're looking for CKEditor to provide a way to follow a link when the user actually wants to open the target, hence the new feature status.

As @wwalc and @duncansimey (in 8251) pointed out, in #439 such feature was introduced for FCK.

Yes, #439 sounds exactly like my suggested approach (CTRL+Click) and I'd be happy with a context menu option too. One thing that doesn't really work well is the Ctrl+right click, since as you already said, IE doesn't support it.

comment:7 in reply to:  6 Changed 13 years ago by Damian

Replying to damo:

Agreed, it is true that browsers disable links in contenteditable containers, but they don't disable CTRL+Click. CKEditor deliberately disables the click (and ctrl+click) event on anchors, see [5751].

To correct myself, it seems that not all browser allow ctrl+click in contenteditable. I've only seen it work in Firefox...

comment:8 Changed 13 years ago by Berend Engelbrecht

Ctrl-click indeed seems to be difficult. However, it is fairly simple to support double click for opening the link. Double click opens the link properties dialog in ckeditor. That is redundant, because the same dialog can also be opened through an option in the right-click menu.

To make double click open the link for an a element in a new window, it is possible to do something like this: Find the double click handler in ckeditor.js. It starts with this code:

X.on('dblclick', function (af) { 
  var ag = af.data.getTarget(), ah = { element: ag, dialog: '' }; 

After the code shown above, insert some code to check whether the element that received the double-click is an a element with a valid http or https link. If so, open the link in a new window. For instance:

if (ag.is('a') && ag.$.href && (ag.$.protocol.indexOf('http') == 0)) { 
  window.open(ag.$.href, '_blank'); af.data.preventDefault(); return; }

Code tested in firefox, chrome, safari, IE7 and IE9.

comment:9 Changed 12 years ago by Robert Easterbrook

This is a real nuisance when editing - when will the "Open Link" item in the context menu be made available in CKeditor please?

comment:10 Changed 12 years ago by markmansour

Cc: mark@… added

comment:11 Changed 11 years ago by Jakub Ś

#1729 was marked as duplicate.

comment:12 Changed 11 years ago by Chevas

Even though the browser is the entity that is disabling the links from being clickable, this is a significant problem for the inline editor. If the inline editor is customer / user facing (and it often is), users need to have the ability to single click a link. This feature should be added.

comment:13 Changed 11 years ago by Jakub Ś

@chevas I have stumbled upon this ticket #10317. I think this is great idea which will allow to keep editor functionality unchanged (blocking links) and would only change “opening editor rules” with config option (which would allow opening links when editor is inactive).

comment:14 Changed 10 years ago by Dr. Gianluigi "Zane" Zanettini, TurboLab.it

Hi all, I found this ticket googling for this exact issue.

I agree that the standard "click to open link" behaviour must be disabled, otherwise it would be an usability hell to work with hyperlinks.

As of CKEditor 4.3.1, the Ctrl+Click works ok on Chrome and Firefox, and this is the right approach for me. Moreover, both display a "Open in a new tab" on the browser-own, non-customized right-click menu. This is golden.

Unfortunately, the issue is that neither work on Internet Explorer: no Ctrl+Click, no right-click, so I can't open my hyperlinks in any mind-sane way.

I tried some jQuery workaround, but IE automatically select my whole paragraph on Ctrl+click: the workaround result is extra-clunky (you have to click, click again, do some voodoo dance and then the link still got opened twice)...

So I think this is something that must be fixed at CKEditor level. What do you think?

comment:15 Changed 10 years ago by Jakub Ś

Keywords: Support added

This issue has been requested on our support channel.

comment:16 Changed 10 years ago by Wiktor Walc

Can you please check the following plugin (prototype) and let us know your feedback?

https://github.com/mlewand/ckeditor-plugin-openlink

It offers an additional item in the context menu and allows clicking links in read-only mode.

comment:17 Changed 10 years ago by Jonathan

This is a feature we would like to see as well.

comment:18 Changed 10 years ago by Piotrek Koszuliński

cc

comment:19 Changed 10 years ago by Jakub Ś

@jbalinski and everyone else interested in such plugin. In comment:16 @wwalc has shown you sample plugin that could be used as prototype to create CKEditor plugin you ask about.

@wwals has also asked what you think of such plugin; if it is acceptable or not? Unfortunately despite many comments in this ticket, no one has bothered to actually give us any feedback about this plugin.

Could anyone do that now?

comment:20 Changed 10 years ago by Jonathan

The plugin submitted by @wwalc does not work for CTRL+CLICK in IE8, IE9, and IE11 (presumably IE 10 as well but I didn't test it). We implemented something similar without the context menu option so that it would at least work in Chrome and Firefox.

Ultimately the CTRL + Click does not fire the click event in IE for links at all regardless of whether or not the CTRL + Click occurs in a contenteditable element or not. However, the default action that IE takes differs when in a contenteditable element than when not. When a link is in a contenteditable element, the clicked text is selected. When the link is not in a contenteditable element the default action of the browser is to open the link in a new tab/window.

Here are some workarounds that have been posted to the web to overcome this limitation.

  1. Nest a span inside of all links <a href="www.test.com"><span>click here</span></a> http://stackoverflow.com/questions/2694408/ie-7-ctrl-click-opens-a-new-window-how-to-suppress-it
  2. Temporarily set the contenteditable flag on the parent element to false on CTRL keydown, and back to true on CTRL keyup. http://stackoverflow.com/questions/12059211/how-to-make-clickable-anchor-in-contenteditable-div

Both of these approaches are pretty heavy handed. I'd lean towards the first approach if it could be handled natively by CKEditor.

The context menu option provided by @wwalc seems to work well for all browsers. It would be nice if this could be wrapped into the link plugin.

comment:21 Changed 10 years ago by Berend Engelbrecht

What about the solution to use double-click to follow the link, that I suggested 3 years ago? It is easily implemented with minimal code change (see my comment of August 2011) and works in all desktop browsers, including all IE versions. I think by default the double-click does the default action of the right-click context menu, which is by nature redundant.

We have been using this workaround in production since then and our users are happy with it. Many of them double-click by habit on links anyway, so for that group of people it is intuitive.

Last edited 10 years ago by Berend Engelbrecht (previous) (diff)

comment:22 Changed 10 years ago by Piotrek Koszuliński

Thanks for your feedback.

@berend_engelbrecht: Double-click opens link dialog and I think the plugin should not change that by default. We can make this configurable though. For example config.openLink_byCtrl (defaults to true) and config.openLink_byDoubleClick (defaults to false).

@jbalinski: We'll check that CTRL+click issue on IEs. Thanks for the research on this!

comment:23 Changed 10 years ago by Jakub Ś

#12133 was marked as duplicate.

#9810 looks related to this one.

Last edited 10 years ago by Jakub Ś (previous) (diff)

comment:24 Changed 9 years ago by Jakub Ś

#13238 was marked as duplicate.

comment:25 Changed 9 years ago by steph123

#12133 is not a DUP of this ticket. #12133 is about clicking on a link when read-only is on. This is a different subject. When read-only is on, there should be an option to enable links to behave like in a normal (non-editable) page.

Regarding the present ticket, let's keep it about clicking on a link when read-only is off. This can be enabled with CTRL+click (like in MS Word), with an additional item in the context menu (which seems the most natural solution), or whatever.

The fact that a prototype plugin (​​https://github.com/mlewand/ckeditor-plugin-openlink) tries to address both issues does not make them the same. But we definitely need a solution to both. Every editor I know allows opening links, in one way or another.

comment:26 Changed 9 years ago by steph123

In terms of features, the plugin proposed by @wwalc is exactly what is needed (it also solve #12133). I think it should be made part of ckeditor.

comment:27 Changed 9 years ago by Piotrek Koszuliński

Not every plugin must be a part of the CKEditor. We are not able to maintain countless features ourselves, so there's the addons repo and the whole API to create new features. If you need this feature there's no problem with including mlewand's plugin in your build. You can also fork the repo and modify the plugin as long as you adhere to the license conditions of the original work.

Of course, I agree that it would be nice to have this feature between other official plugins, but I can't promise that we'll have time to work on this.

comment:28 Changed 9 years ago by steph123

I understand your concern about the growing number of features. Nevertheless, here is how I feel:

  • In read only mode, the fact that clicking on a link has no effect (#12133) should be considered a bug.
  • When read only is off, offering a way to open a link should be part of an official plugin. Couldn't it be integrated to "Context Menu"?

comment:29 Changed 9 years ago by Piotrek Koszuliński

I understand that you may feel this way, but we need to remember that:

  • Other developers want something opposite to what you want. E.g. in some CMS-es such links will be relative to the target page's website and hence may not work in the admin panel. So it's not that super clear what should be the default behaviour. I'm pretty sure that many years ago someone requested that links shouldn't be clickable.
  • The code must be modular to avoid bloating the code with features which developers may not want. Therefore the link plugin should do just one thing - allow inserting and editing links. While additional functionalities like support for opening links should be added by another plugins.

comment:30 Changed 9 years ago by steph123

Makes sense.

comment:31 Changed 9 years ago by Jakub Ś

#13556 was marked as duplicate.

comment:32 Changed 9 years ago by Piotrek Koszuliński

#13702 was marked as duplicate.

comment:33 Changed 8 years ago by Jakub Ś

#14748 was marked as duplicate

comment:34 in reply to:  8 Changed 8 years ago by marvin_r

Replying to berend_engelbrecht:

Ctrl-click indeed seems to be difficult. However, it is fairly simple to support double click for opening the link. Double click opens the link properties dialog in ckeditor. That is redundant, because the same dialog can also be opened through an option in the right-click menu.

To make double click open the link for an a element in a new window, it is possible to do something like this: Find the double click handler in ckeditor.js. It starts with this code:

X.on('dblclick', function (af) { 
  var ag = af.data.getTarget(), ah = { element: ag, dialog: '' }; 

After the code shown above, insert some code to check whether the element that received the double-click is an a element with a valid http or https link. If so, open the link in a new window. For instance:

if (ag.is('a') && ag.$.href && (ag.$.protocol.indexOf('http') == 0)) { 
  window.open(ag.$.href, '_blank'); af.data.preventDefault(); return; }

Code tested in firefox, chrome, safari, IE7 and IE9.

This is exactly what I am looking for, but I'm using a newer version of the editor. Does anyone have this working in CKeditor v4.5? If yes, which code is necessary where? Thanks!

Last edited 8 years ago by marvin_r (previous) (diff)

comment:35 Changed 7 years ago by istrasoft

Actually I sucessfully implemented the modification in the minified version of CKEditor 4.6.2

Look for the beginning of the code block here, and add the modifications below. Careful, you have to replace the whole block here, not only add what's in between comments.

c.on('doubleclick',function(e){var b=CKEDITOR.plugins.link.getSelectedLink(c)||e.data.element;if(!b.isReadOnly()){if(b.is('a')){	
/*new code*/ if (b.$.href&&(b.$.protocol.indexOf('http')==0)){window.open(b.$.href,'_blank');e.data.preventDefault();return;}/*end new code*/else
{e.data.dialog=(b.getAttribute('name')&&(!b.getAttribute('href')||!b.getChildCount()))?'anchor':'link';e.data.link=b;}}else
 if(CKEDITOR.plugins.link.tryRestoreFakeAnchor(c,b)){e.data.dialog='anchor';}}},null,null,0);
Note: See TracTickets for help on using tickets.
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy