Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

innerhtml

Status
Not open for further replies.
Jan 26, 2001
550
0
0
GB
Hi,

Not sure if this is right forum but I have a problem with innerHTML.

I am using a content-editable div within a content management application. The user can edit their details with the wysiwyg editor and put in bolds, hyperlinks etc.
The div can also be changed to display the raw html by clicking a button.

On submission of the form, my code looks at what type of content is within the div, if it is raw HTML it takes the innerText, and if it is WYSIWYG it takes the innerHTML.

This is where my problem occurs - the conversion to innerHTML automatically converts the characters to their html equivalents. This is good in most ways, but it is messing up my links. On a second submission of pre-saved html, The &quot;s within the <a> tag are replaced with '&quot; which breaks the links.

I cannot find a solution to this anywhere, and I am thinking that regular expressions could be the only answer.

Does anyone have an ideas?

Nick (Webmaster)

info@npfx.com
 
Without seeing your code, it appears that you're using double quotes throughout. Change the &quot;s to 's and see if helps.

There's always a better way. The fun is trying to find it!
 
You could encode all of the quotes (both double and single) using their HTML equivalent values. Double quotes can be represented with #34 ([ignore]&amp;&#35;34&#59;[/ignore]), while the single quote (apostrophe) can be represented with #39 ([ignore]&amp;&#35;39&#59;[/ignore]).

Hope this helps.

Pete.


Web Developer &amp; Aptrix / Lotus Workplace Web Content Management (LWWCM) Specialist
w: e: Pete.Raleigh(at)lclimited.co.uk
 
Are you sure it's not URL encoding that is messing with the &quot; characters?

----------
I'm willing to trade custom scripts for... [see profile]
 
Good point stormbind.

Howard - what do you mean by it &quot;breaks the links&quot;? Are you getting JavaScript errors on the page, or is the URL in the address bar simply incorrect? Futher information would be really helpful.

Pete.


Web Developer &amp; Aptrix / Lotus Workplace Web Content Management (LWWCM) Specialist
w: e: Pete.Raleigh(at)lclimited.co.uk
 
Heya guys,

thanks for your input. perhaps this will clarify:

The problem is the re-writing of the actual html. The wysiwyg editor allows the users to type in their details, and one of the functions of the editor is that it picks up web addresses and creates hyperlinks out of them.

this is great, apart from that the actual html of the hyperlink is getting rewritten. I don't have any control over how these hyperlinks are written (i.e. with a ' or a &quot;) because the ms wyswiwg engine is automatically creating them.

once the page is saved, the inner html is saved to the database. This is where the error occurs.

For example what should be <a href=&quot; becomes <a href='&quot; which is incorrect syntax.

For a much clearer and better demonstration in which you can see this problem actually happening - go to and create a new account (don't worry it wont go live on the website until i have authorised it). Once the account is created play around with the wysiqyg text boxes and create some links, then save it and see what happens to the HTML.

this one is doing my head in but i don't know if theres a way ropund it, or indeed understand exactly what is causing the error.

I hope you can help

cheers

Nick

Nick (Webmaster)

info@npfx.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top