I was about to post a resolution to my issue with making a custom VF function for inserting hyperlinks with title/alt-text, when I ran into a problem with the javascript I'm using in the HTML page that's being run for the form to be filled in -- and I'm hoping someone here can make sense of this -- and better yet, tell mehow I can fix it.
To start off with - Ektron provides a function for getting the HTML associated with the selected text - so that when you select something like
some text you'd actually get a string that looks like "
<a title="foo bar baz" href="//some_text" target=_blank>" (their routine automatically strips double-quotes from around attribute values that don't contain white-space [ugh]) - so I wrote this code (selectedHTML contains the string as indicated above):
...
var target = '';
...
if (selectedHTML.match(/target="/)){
target = selectedHTML.replace(/^.*target="([^"]+)".*$/, "$1");
}
else if (selectedHTML.match(/target='/)){
target = selectedHTML.replace(/^.*target='([^']+)".*$/, "$1");
}
else if (selectedHTML.match(/target=/)){
target = selectedHTML.replace(/^.*target\s*=\s*([^\s>]+)[\s>].*$/, "$1");
}
alert("target: "+target); //#=#
...Now if the actual selectedHTML code associated with the text I have selected in VFE is:
<A title=0123456789013456789 href="/graphics/sentry.jpg" target=_blank>ddd</A>then everything works out fine, and the alert shows:
target: _blankHowever, if the actual selectedHTML code associated with the text I have selected in VFE is:
<A title=01234567890123456789 href="/graphics/sentry.jpg" target=_blank>ddd</A>then the alert shows:
target: <A title=01234567890123456789 href="/graphics/sentry.jpg" target=_blank>ddd</A>I can find no reference to the replace() function having a string length limitation - the total string length we're talking about here is around 54 characters -- and I've gotten it to fail the same way with strings identical in length to that which worked - like:
<A title=01 3456789013456789 href="/graphics/sentry.jpg" target=_blank>ddd</A>(
note space where first 2 used to be)
sometimes it will even work a few times and then fail without my having changed anything!
Anyone have any ideas?
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com