You are not logged in.
Pages: 1
I'm a newbie, I have a problem with create in wysiwyg mode. create new link like this
<a href="#top" target="_self">mynewlink</a>,
after that submit and re-open, link atomatic change to <a href="http://www.mysite.com/somedir/#top" target="_self">mynewlink</a> after I open link property.
How can I keep href like the first time I inputed it?
Offline
First, is HTMLArea.stripSelfNamedAnchors = true? I think this is the default, but if not than that is definitely your problem. HTMLArea.baseHref and HTMLArea.stripBaseHref should probably also be set.
Myself, I ended up having to totally change htmlarea.js to fix this problem. If you know enough javascript to tinker, look at: outwardHtml() and inwardHtml () (the urls are made absolute for IE there), fixRelativeLinks() (where it should be stripping the base url out), and stripBaseURL() (which is called when adding links, images, and in getHTML() to fix IE urls).
I ended up stripping out the absolutes in outwardHtml and inwardHtml and adding a new function to wrap stripBaseURL() and replacing every call to stripBaseURL() with a call to this instead:
HTMLArea._fixIELink = function(node,nodeType,editor) {
var value=(nodeType=="href")?node.href:node.src;
if (HTMLArea.is_ie)
{
var rx=(nodeType=="href")?/href="([^"]+)"/i:/src="([^"]+)"/i;
var match=rx.exec(node.outerHTML+"");//--relative urls correct here
if (match && match[1]) value=match[1];
}
return editor.stripBaseURL(value);
};
But that was a real pain in the butt to get working.
Last edited by mleiv (2006-03-23 15:45:34)
Offline
Just an update for those interested. When testing, I had to add *another* link converter to the mix (_fixIELinks(), included below), after the body.innerHTML change in setHTML(). I also tinkered with the original _fixIELink() to handle some other href formats. The result is really DOM/regexp heavy (IE 6+ only), but it seems to run without noticeable delays.
HTMLArea._fixIELink = function(node,nodeType,editor) {
var value=(nodeType=="href")?node.href:node.src;
if (HTMLArea.is_ie)
{
var match=(node.outerHTML+"").match(/(href|src)=("[^"]*"|'[^']*'|[^\s]*)/i);
if (match && match[2]) value=match[2].replace(/(^["']|["']$)/g,"");
}
return editor.stripBaseURL(value);
};
HTMLArea._fixIELinks=function(html,editor){
if (!HTMLArea.is_ie) return;
var matches=html.match(/<a(?: [^>]+)?>/ig);
var nodes=editor._doc.body.getElementsByTagName("a");
for (var i=0;i<nodes.length;i++)
{
if (!matches[i]) continue;
var match=(matches[i]).match(/href=("[^"]*"|'[^']*'|[^\s]*)/i);
if (match && match[1]) nodes[i].href=match[1].replace(/(^["']|["']$)/g,"");
}
var matches=html.match(/<img(?: [^>]+)?>/ig);
var nodes=editor._doc.body.getElementsByTagName("img");
for (var i=0;i<nodes.length;i++)
{
if (!matches[i]) continue;
var match=(matches[i]).match(/src=("[^"]*"|'[^']*'|[^\s]*)/i);
if (match && match[1]) nodes[i].src=match[1].replace(/(^["']|["']$)/g,"");
}
};
And now I promise not to post more frivolous tinkering code for a few days... ;)
Last edited by mleiv (2006-03-23 16:58:42)
Offline
Thanks mleiv, but in this case I use FireFox, did you test this code in FireFox?
I'm newbie, so I don't know what's different between FireFox and IE 6.0?
You talked that replacing every call to stripBaseURL() with a call to _fixIELink() instead, but _fixIELink() has 3 parameters while stripBaseURL() has only 1 parameter, could you tell me more detail in this case?
Offline
If you are only using Firefox, you do not need the new functions at all (they only work for IE anyway). I think that properly setting HTMLArea.stripSelfNamedAnchors = true, HTMLArea.baseHref = [http://your_server], and HTMLArea.stripBaseHref = true, should be all you need.
But if that doesn't work, then you can try commenting out the absolute url convert in inwardHtml() and outwardHtml(). The first one looks like this:
html = html.replace(/((href|src|background)=[\'\"])\/+/ig, '$1' + serverBase);
and the second one looks like this:
var nullRE = new RegExp('((href|src|background)=[\'"])/+', 'gi');
html = html.replace(nullRE, '$1' + location.href.replace(/(https?:\/\/[^\/]*)\/.*/, '$1') + '/');
This is what I myself have done, but I did most of my hacking *before* I discovered HTMLArea.baseHref, so it may have been totally unnecessary and there may be side-effects I haven't noticed yet. I'm no Xinha expert, I just tinker with the parts that cause me problems.
Offline
Thanks for the response, I was set HTMLArea.stripSelfNamedAnchors = true, HTMLArea.baseHref = null and HTMLArea.stripBaseHref = true, but it didn't work. But do you think problem occur in this line?
// IE puts this in can't figure out why
html = html.replace(/https?:\/\/null\//g, serverBase);
because if we use '//' anything stand after it of course become comment.
so if you add alert statement like this after that code : alert(html), error script will occur
Last edited by alibaba_and_40girls (2006-03-24 03:21:08)
Offline
You must set HTMLArea.baseHref to your server base url, not null. If it were this page that Xinha was loading on, baseHref="http://xinha.gogo.co.nz/punbb/"
The line you reference is not the problem. It only replaces http://null/ in urls, which never happens in Firefox.
Offline
You must set HTMLArea.baseHref to your server base url, not null. If it were this page that Xinha was loading on, baseHref="http://xinha.gogo.co.nz/punbb/"
Oh man, I know that, but it's not my problem now, please read my post on the top
I only want <a href="#top" target="_self">mynewlink</a>, I don't want add anything into my href when Xinha loading on.
Thank you anyway .
Offline
If you are using the GetHtml plugin, make sure you have the latest version. I posted an update to it last week that fixes a problem that sometimes occured in IE with self-named anchors.
Offline
Yes, I was update the lastest version but I'm using FireFox, not IE. Although it's still occur this problem.
Offline
Hi mleiv,
Have just been following this thread as I have the same issue with relative anchors in IE (works ok in Firefox).
There was reference to the new fix HTMLArea._fixIELink = function(node,nodeType,editor) { .....
to replace the stripBaseURL().
Could you clarify the 3 params being passed through, as the code I currently have only passes a url value to the current stripBaseURL() function. Am I missing additional code (that you wrote) that defines the 3 params being sent through to the new fixIELink function?
Cheers,
Trem
Offline
Pages: 1