Firefox NicEdit链接创建不需要';如果文本不是';t选择
我对IE和Firefox中的nicEdit链接创建工具有问题 一般来说,我认为问题与IE和FireFox中的Firefox NicEdit链接创建不需要';如果文本不是';t选择,firefox,internet-explorer-8,hyperlink,nicedit,execcommand,Firefox,Internet Explorer 8,Hyperlink,Nicedit,Execcommand,我对IE和Firefox中的nicEdit链接创建工具有问题 一般来说,我认为问题与IE和FireFox中的execCommand有关。执行execCommand后,文档似乎不会得到更新 这是我的nicEdit create link命令问题的一个例子 if(!this.ln) { var tmp = 'javascript:nicTemp();'; this.ne.nicCommand("createlink",tmp); this.ln = t
execCommand
有关。执行execCommand
后,文档似乎不会得到更新
这是我的nicEdit create link命令问题的一个例子
if(!this.ln) {
var tmp = 'javascript:nicTemp();';
this.ne.nicCommand("createlink",tmp);
this.ln = this.findElm('A','href',tmp);
// set the link text to the title or the url if there is no text selected
alert(this.ln);
if (this.ln.innerHTML == tmp) {
this.ln.innerHTML = this.inputs['title'].value || url;
};
}
上面的代码在未选择文本时被调用,Chrome为警报(this.ln)
返回'javascript:nicTemp()'
,而IE 8和Firefox返回'undefined'
,因此警报后的下一行在IE和Firefox中遇到错误
似乎findElem
无法通过nicCommand
找到新创建的链接,后者依次调用execCommand
当我试图查找和修改用execCommand
创建的标记时,我遇到了类似的问题,似乎dom没有更新以包含它们
我说得对吗?我怎样才能解决这个问题?如何强制更新文档
请帮助在未选择任何文本的情况下,我的nicEdit技巧是将通过“添加链接”表单提供的标题粘贴到文档中并选择它,然后其余代码的工作方式与选择文本时的工作方式相同
我使用了下面链接中描述的函数pasteHtmlAtCaret来粘贴标题
getSelected也是一个简单的函数,如下所示
function getSelected()
{
if (document.selection)
return document.selection.createRange().text;
else
return window.getSelection();
}
在没有选择任何文本的情况下,我对nicEdit的技巧是将通过addlink表单给出的标题粘贴到文档中并选择它,然后其余代码的工作方式与选择文本时的工作方式相同
我使用了下面链接中描述的函数pasteHtmlAtCaret来粘贴标题
getSelected也是一个简单的函数,如下所示
function getSelected()
{
if (document.selection)
return document.selection.createRange().text;
else
return window.getSelection();
}
Ahmad,只需使用“提交”功能的这个变体,以避免链接的“插入/编辑”问题,它对我有效:
submit : function(e) {
var url = this.inputs['href'].value;
if(url == "http://" || url == "") {
alert("Introduce una URL valida para crear el Link.");
return false;
}
this.removePane();
if(!this.ln) {
//**************** YOUR CHANGE WITH A BIT OF VARIATION **************
var selected = this.getSelected();
var tmp = 'javascript:void(0)';
if (selected == '') {
tmp = url;
this.pasteHtmlAtCaret(this.inputs['title'].value || tmp, true);
}
//**************** END OF YOUR CHANGE WITH A BIT OF VARIATION **************
this.ne.nicCommand("createlink",tmp);
this.ln = this.findElm('A','href',tmp);
// set the link text to the title or the url if there is no text selected
if (this.ln.innerHTML == tmp) {
this.ln.innerHTML = this.inputs['title'].value || url;
};
}
if(this.ln) {
var oldTitle = this.ln.title;
this.ln.setAttributes({
href: this.inputs['href'].value,
title: this.inputs['title'].value,
target: '_blank'
});
// set the link text to the title or the url if the old text was the old title
if (this.ln.innerHTML == oldTitle) {
this.ln.innerHTML = this.inputs['title'].value || this.inputs['href'].value;
};
}
}
Ahmad,只需使用“提交”功能的这个变体,以避免链接的“插入/编辑”问题,它对我有效:
submit : function(e) {
var url = this.inputs['href'].value;
if(url == "http://" || url == "") {
alert("Introduce una URL valida para crear el Link.");
return false;
}
this.removePane();
if(!this.ln) {
//**************** YOUR CHANGE WITH A BIT OF VARIATION **************
var selected = this.getSelected();
var tmp = 'javascript:void(0)';
if (selected == '') {
tmp = url;
this.pasteHtmlAtCaret(this.inputs['title'].value || tmp, true);
}
//**************** END OF YOUR CHANGE WITH A BIT OF VARIATION **************
this.ne.nicCommand("createlink",tmp);
this.ln = this.findElm('A','href',tmp);
// set the link text to the title or the url if there is no text selected
if (this.ln.innerHTML == tmp) {
this.ln.innerHTML = this.inputs['title'].value || url;
};
}
if(this.ln) {
var oldTitle = this.ln.title;
this.ln.setAttributes({
href: this.inputs['href'].value,
title: this.inputs['title'].value,
target: '_blank'
});
// set the link text to the title or the url if the old text was the old title
if (this.ln.innerHTML == oldTitle) {
this.ln.innerHTML = this.inputs['title'].value || this.inputs['href'].value;
};
}
}
this.removePane();
var url=this.inputs['href'].value;
var selected=getSelected();
var isChrome=/Chrome/.test(navigator.userAgent)和&/googleinc/.test(navigator.vendor);
var tmp=“”;
如果(isChrome==真){
tmp=url;
}
else{tmp='javascript:nicTemp()'}
如果(所选=''&&isChrome==假)
{
pasteHtmlAtCaret(this.inputs['title'].value | | url,true);
}
如果(!this.ln){
//var tmp=this.inputs['title'].value==“”?this.inputs['href'].value:this.inputs['title'].value;
这个.ne.nic命令(“createlink”,tmp);
this.ln=this.findElm('A','href',tmp);
}
函数getSelected()
{
if(文档选择)
return document.selection.createRange().text;
其他的
返回window.getSelection();
}
函数pasteHtmlAtCaret(html){
var-sel,范围;
if(window.getSelection){
//IE9和非IE
sel=window.getSelection();
if(sel.getRangeAt&&sel.rangeCount){
范围=选择范围(0);
range.deleteContents();
//Range.CreateContexturalFragment()在这里会很有用,但是
//非标准且并非所有浏览器都支持(例如IE9)
var el=document.createElement(“div”);
//创建链接格式
el.innerHTML='';
var frag=document.createDocumentFragment(),节点,lastNode;
while((node=el.firstChild)){
lastNode=frag.appendChild(节点);
}
range.insertNode(frag);
//保留所选内容
如果(最后一个节点){
range=range.cloneRange();
range.setStartAfter(lastNode);
范围。塌陷(真);
选择removeAllRanges();
选择添加范围(范围);
}
}
}else if(document.selection&&document.selection.type!=“控制”){
//IE<9
document.selection.createRange().pasteHTML(html);
}
}
此.removePane();
var url=this.inputs['href'].value;
var selected=getSelected();
var isChrome=/Chrome/.test(navigator.userAgent)和&/googleinc/.test(navigator.vendor);
var tmp=“”;
如果(isChrome==真){
tmp=url;
}
else{tmp='javascript:nicTemp()'}
如果(所选=''&&isChrome==假)
{
pasteHtmlAtCaret(this.inputs['title'].value | | url,true);
}
如果(!this.ln){
//var tmp=this.inputs['title'].value==“”?this.inputs['href'].value:this.inputs['title'].value;
这个.ne.nic命令(“createlink”,tmp);
this.ln=this.findElm('A','href',tmp);
}
函数getSelected()
{
if(文档选择)
return document.selection.createRange().text;
其他的
返回window.getSelection();
}
函数pasteHtmlAtCaret(html){
var-sel,范围;
if(window.getSelection){
//IE9和非IE
sel=window.getSelection();
if(sel.getRangeAt&&sel.rangeCount){
范围=选择范围(0);
range.deleteContents();
//Range.CreateContexturalFragment()在这里会很有用,但是
//非标准且并非所有浏览器都支持(例如IE9)
var el=document.createElement(“div”);
//创建链接格式
艾尔·因内尔