Announcement

Do not use the forums to submit bug reports, feature requests or patches, submit a New Ticket instead.

#1 2006-03-23 05:44:05

alibaba_and_40girls
Xinha Community Member
Registered: 2006-03-23
Posts: 11

problem with link. help me!

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

#2 2006-03-23 15:10:03

mleiv
New member
Registered: 2006-03-23
Posts: 8

Re: problem with link. help me!

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

#3 2006-03-23 16:58:07

mleiv
New member
Registered: 2006-03-23
Posts: 8

Re: problem with link. help me!

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

#4 2006-03-23 20:08:34

ray
Xinha Administrator
From: Germany
Registered: 2005-03-23
Posts: 521
Website

Re: problem with link. help me!

If this is really doing a good job you should create a patch and  submit a ticket

Offline

#5 2006-03-24 00:00:50

alibaba_and_40girls
Xinha Community Member
Registered: 2006-03-23
Posts: 11

Re: problem with link. help me!

Thanks mleiv, but in this case I use FireFox, did you test this code in FireFox? big_smile
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? smile

Offline

#6 2006-03-24 01:11:41

mleiv
New member
Registered: 2006-03-23
Posts: 8

Re: problem with link. help me!

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. sad  I'm no Xinha expert, I just tinker with the parts that cause me problems.

Offline

#7 2006-03-24 03:20:10

alibaba_and_40girls
Xinha Community Member
Registered: 2006-03-23
Posts: 11

Re: problem with link. help me!

Thanks for the response, smile 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 sad

Last edited by alibaba_and_40girls (2006-03-24 03:21:08)

Offline

#8 2006-03-24 12:53:12

mleiv
New member
Registered: 2006-03-23
Posts: 8

Re: problem with link. help me!

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

#9 2006-03-24 22:04:51

alibaba_and_40girls
Xinha Community Member
Registered: 2006-03-23
Posts: 11

Re: problem with link. help me!

mleiv wrote:

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 smile
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 smile.

Offline

#10 2006-03-25 10:30:20

wymsy
Xinha Community Member
From: Massachusetts, USA
Registered: 2005-04-01
Posts: 44
Website

Re: problem with link. help me!

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

#11 2006-03-26 04:06:25

alibaba_and_40girls
Xinha Community Member
Registered: 2006-03-23
Posts: 11

Re: problem with link. help me!

Yes, I was update the lastest version but I'm using FireFox, not IE. Although it's still occur this problem.

Offline

#12 2006-08-25 02:48:48

trem
New member
From: Australia
Registered: 2005-04-22
Posts: 1

Re: problem with link. help me!

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

Board footer

Powered by FluxBB