0
votes

I am uses TinyMCE 4 where I have inserted source content as link

<a href="http://google.com">Sample Link</a>

After inserting above content in the TinyMCE, if I click on the preview button of TinyMCE then anchor tag is coming in the form of link but it's not clickable.

Can anyone guide how anchor we can make it as clickable?

I have followed below links(by adding default_link_target: "_blank"): https://community.tinymce.com/communityQuestion?id=90661000000MrWjAAK & How to open hyperlink in new window under tinymce text editor? but none seems to be worked.

but none seems to be worked.

2

2 Answers

1
votes

The preview plugin has code that specifically stops links from being clickable. If you look at the JavaScript code for the plugin you will see something like this:

var preventClicksOnLinksScript = (
  '<script>' +
    'document.addEventListener && document.addEventListener("click", function(e) {' +
        'for (var elm = e.target; elm; elm = elm.parentNode) {' +
          'if (elm.nodeName === "A") {' +
           'e.preventDefault();' +
          '}' +
        '}' +
    '}, false);' +
  '</script> '
);

This code is there specifically to address an issue that could cause a link in preview to unintentionally remove the editor instance.

If you click a link in the preview pane that has a target=_top you will end up blowing away the editor and replacing it with the content of that link - likely not what you want.

0
votes

I know it's an old thread but maybe it will help someone out there. If you want the links to open in a new window in tinymce prevew plugin remove this script:

<script>document.addEventListener && document.addEventListener("click", function(e) {for (var elm = e.target; elm; elm = elm.parentNode) {if (elm.nodeName === "A") {e.preventDefault();}}}, false);</script>

and place this one instead:

<script>function externalLinks() { for(var c = document.getElementsByTagName("a"), a = 0;a < c.length;a++) { var b = c[a]; b.getAttribute("href") && b.href.hostname !== location.hostname && (b.target = "_blank") } } ; externalLinks();<\/script>

Enjoy!