Is there way to prepend 'http://' to URL if it's not there while adding URL with Insert Link in TinyMCE?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
For that you would need to copy the tinymce Insert Link plugin, rename it, add the necessary code to it (the "http"-Adding) and use it as your own plugin.
EDIT: Ok, here is an example (using jQuery):
// You might need to change the event and/or tha handling
// but this should give you a guess at what needs to be done
setup : function(ed)
{
ed.onClick.add(function(ed, evt)
{
$(ed.getBody()).find('a').each(function(index, element){
if (!$(this).attr('href').search('http')){
$(this).attr('href', 'http://' + $(this).attr('href'));
}
});
});
},
回答2:
I was facing this problem as well with version 4.x. I discovered that the link
plugin supports an option that prompts the user to add the protocol. But unfortunately it's not mentioned in the documentation, it's only documented in the changelog so I would imagine this is widely unknown.
$('textarea').tinymce({
...
link_assume_external_targets: true
...
});
回答3:
I have achieved this by prepopulating the field value with 'http://' in the tinymce insertLink.aspx file.
<ui:PropertyPanel runat="server" Text="Url">
<input type="hidden" id="localUrl" name="localUrl" onchange="" />
<input id="href" name="href" type="text" style="width: 220px;" value="http://" onchange="document.getElementById('localUrl').value = '';
selectByValue(this.form,'linklisthref',this.value);" />
</ui:PropertyPanel>
value="http://"
回答4:
in link.js, find "if (!f.href.value)"
add an "else" clause
else {
var href = f.href.value;
if (href.indexOf('http') == -1) {
href = 'http://' + href;
f.href.value = href;
}
}
** remember that you did that in case you update your tinymce component!