Won't fix
Last Updated: 28 Jun 2016 16:24 by ADMIN
ADMIN
Ianko
Created on: 25 Oct 2013 13:27
Category: Editor
Type: Bug Report
1
Fix when switched to Preview mode and back, the onclick attribute of the anchor elements are being stripped and in Preview mode all links are clickable under IE7
When a Hyperlink element is set with an onclick handler, after passing through the Preview mode it is being stripped under IE7. Also related problem is that the link in the Preview mode are clickable and the URL set to the href attribute is opened in new tab/window.

Possible solution for both bugs is to override the function responsible for the conversion of such attributes in the Preview mode with this JavaScript code:

Telerik.Web.UI.Editor.Utils.setTargetsForPreview = function (editor) {
	var contentArea = editor.get_contentArea();
	var links = contentArea.getElementsByTagName("A");
	for (var i = 0, l = links.length; i < l; i++) {
		var link = links[i];
		//handle targets
		var target = link.getAttribute("target");
		if (target != null) {
			link.setAttribute("re_target", target);
		}
		if (target != "_blank")
			link.setAttribute("target", "blank");
		//handle ckick event
		var oldOnClick = (link.getAttributeNode('onclick')
			&& link.getAttributeNode('onclick').value)
			|| link.getAttribute("onclick");

		if (oldOnClick != null) {
			link.setAttribute('re_onclick', oldOnClick);
		}

		link.setAttribute('onclick', 'return false;');

		if (typeof link.onclick === "string") {
			link.onclick = function () {
				return false;
			};
		}
	}
};

Telerik.Web.UI.Editor.Utils.restoreTargetsAfterPreview = function (editor) {
	var contentArea = editor.get_contentArea();
	var links = contentArea.getElementsByTagName("A");
	for (var i = 0, l = links.length; i < l; i++) {
		var link = links[i];
		//handle targets
		var oldValue = link.getAttribute("re_target");
		if (oldValue != null && oldValue != "null") {
			link.setAttribute("target", oldValue);
		}
		else {
			link.removeAttribute("target");
		}
		//handle anchors urls
		var oldOnClick = link.getAttribute("re_onclick");
		link.onclick = null;
		if (oldOnClick != null && oldOnClick != "null") {
			link.setAttribute('onclick', oldOnClick);
		}
		else {
			link.removeAttribute("onclick");
		}
		link.removeAttribute("re_onclick");
		link.removeAttribute("re_target");
	}
};


Note that this script must be placed in a script tag right after the RadEditor control.
(Total attached files size should be smaller than 20mb. Allowed extensions: .zip, .rar, .jpg, .png, .gif)
5 comments
ADMIN
Niko
Posted on: 28 Jun 2016 16:24
Since the Telerik UI for ASP.NET AJAX no longer supports IE7 this issue is not relevant.
Anbu
Posted on: 25 Nov 2013 09:27
I am using 2011.2.712.35 version and upgraded the 2012.3.1205.35 ...but not working pls help
Anbu
Posted on: 25 Nov 2013 09:24

I am using RadEditor  i have a problem, when <a> tag is not closed then its rendering unwanted duplicate tags.

Before:
<a class="inorya" href="#menu" target="blank"> click to go</a></p>

After:
<p>
<a class="inorya" href="#menu" target="blank"> click to go</p>

Expected Output:

<a class="inorya" href="#menu" target="blank"> click to go</a></p>

when i change to some other view say design or preview and again after returning to html i get 

<p>
<a class="inorya" href="#menu" target="blank"> click to go</a></p>
<a class="inorya" href="#menu" target="blank">
<p>

Thanks in advance
Anbu
Posted on: 18 Nov 2013 11:53
yes working now. thanks for solution.
Chris
Posted on: 25 Oct 2013 14:50
I have confirmed that this does work. However I had to put this code in OnClientLoad because my RadEditor is built and loaded from the backend.