Copy link to clipboard
Copied
I have a LinkElement in a RichEditableText's textflow. The link's href has encoded spaces in it (%20).
If I catch a click event and debug down to the LinkElement level the href still appears correct, however when it opens in new browser tab the url has been re-encoded
ie %20 is now %2520 - as the % sign has itself been encoded. Is there a way that I can stop this behavior?
Thanks
Copy link to clipboard
Copied
Hi davidg84, You can uses real space in your URL, like "www.abc.com/bcd def.html", then TLF will help you handle your spaces.
Copy link to clipboard
Copied
Thanks for your answer, my issue though is that users can enter in abritrary links, they may paste them from an address bar and be unaware of url encoding. What I'd prefer is for the url to be assumed correct and not encoded.
Is there somewhere I can intercept before the url gets encoded again?
Copy link to clipboard
Copied
In your case, the only way is after you get users' input, handle the url by yourself, remove %20 and replace it with space, then pass the new url to TLF. Hope this helps.
Copy link to clipboard
Copied
I've addressed it as follows, when the RichEditableText renders, a function adds an event listener to each LinkElement, the handler does this:
if(event.flowElement && event.flowElement is LinkElement) {
var linkElement:LinkElement = event.flowElement as LinkElement;
var href:String = linkElement.href;
// if its a mailto link, stop here
if(href.indexOf("mailto:") == 0) {
return;
}
// Do not encode URL - navigate will handle it
var url:URLRequest = new URLRequest(href);
navigateToURL(url, linkElement.target);
event.preventDefault();
event.stopImmediatePropagation();
}
}
This seems to handle both encoded and unencoded urls. So i can leave the users input as they intend it.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now