Where to do this?
The environment is a java web app with jquery and jquery-ui on the front end. There is an admin site where they can create content that appears on the "participant" site.
The client wants a WYSIWYG type editor on the admin site so they can stick HTML into textareas that appear on the participant site. I've been looking at a few of them, and did some experiments with cleditor and it seems to be easy to use and it does most of what I want. I was also advised to use the AntiSamy plugin on the back end to prevent their "admins" from adding malicious code - I guess they don't trust their admins all that much.
But I've got one requirement that has me scratching my head. They want any hyper links added to the textareas to go into another window (and not a different window each time). So basically they want a target="myWindow"
in each href, I guess. And they want this to apply whether they create the hyperlink in the editor, or if they paste a Word document that has a hyperlink in it, which appears to be something they do a lot.
My question is how to go about applying this target
to all the hrefs. Is there a wysiwyg editor that will do it, or c开发者_运维问答an it be done in the AntiSamy plugin (since it's already parsing the html) or do I need to do it somewhere between the two?
I would handle it in the JavaScript on the page as the user submits the form. You can iterate through all of the anchor tags and add the necessary target bits to the end. The process would be similar to the answer here:
jQuery - Change the anchor tag in CLEditor
I would do it after the data has been posted. Its pretty easy to parse the HTML with JSOUP and add a new target to it. You could do it with RegEx also.
Another option is to use javascript and easily add
$(".somediv a").attr('target', '_blank');
Last option, if you are not aware of the base tag. You can do <base target='_blank'/>
which will make ALL your hrefs a new target.
Edit -
Also as Justin pointed out, you can process the href before posting. I wasn't aware that CKEdit had this option. This is probably the better solution.
精彩评论