HtmlEditor :  Phorum 5 The fastest message board... ever.

This is the discussion forum for the HtmlEditor. See also the HtmlEditor home page, where you can download the control, and the Documentation Wiki, a collaborative project for documenting the control.

Goto Thread: PreviousNext
Goto: Forum ListMessage ListNew TopicSearchLog In
GetDocumentSource adds unwanted HTML
Posted by: Eric (66.100.119.---)
Date: Tuesday, 14-Oct-2003, 16:06:14

I have two forms, each with an instance of the HTMLEditor control.

Form1's HTMLEditor has IsDesignMode = False
Form2's HTMLEditor has IsDesignMode = True

Form1 opens Form2 and then..

Form2.HTMLEditor.LoadDocument(Form1.HTMLEditor.GetDocumentSource)

then the source is fine... but after editing in form2, when I set a string to equal the Form2.HTMLEditor.GetDocumentSource I get a bunch of extra HTML including DOCTYPE declaration and a GENERATOR meta tag.

Why does the same method (GetDocumentSource) have different results for the two controls? How do I get the method to NOT add the extra HTML?

I've tried setting IsDesignMode = False before calling GetDocumentSource, but then, the only source I get is <HTML></HTML>

Thanks

Re: GetDocumentSource adds unwanted HTML
Posted by: Tim (---.server.ntli.net)
Date: Tuesday, 14-Oct-2003, 16:17:04

Mshtml does NOT do source preservation. Thus, it feels entitled to add the GENERATOR tag, change tags to upper case, etc, when in design mode.

Very annoying, but I don't know any way around it. Other than to parse HTML after the event.

The old DHTMLEdit ActiveX does sourse preservation, and so do apps like FrontPage (not sure if this uses MSHTML) so there must be a way...

Tim

Re: GetDocumentSource adds unwanted HTML
Posted by: Eric (66.100.119.---)
Date: Tuesday, 14-Oct-2003, 16:24:41

Thanks for replying smiling smiley

It's just weird that the same method call against essentially identical controls produces 2 different results. The first GetDocumentSource does what I want, the 2nd one doesn't... something has to be allowing the 1st call to do what I want, I just can't find it.

Re: GetDocumentSource adds unwanted HTML
Posted by: Tim (---.server.ntli.net)
Date: Wednesday, 15-Oct-2003, 09:08:24

If the DesignMode is False, then there's no need for MSHTML to reformat the code.

Tim

Re: GetDocumentSource adds unwanted HTML
Posted by: Eric (66.100.119.---)
Date: Wednesday, 15-Oct-2003, 14:04:08

that's just it, when I set DesignMode to false, then GetDocumentSource only returns "<HTML></HTML>"

:/

Re: GetDocumentSource adds unwanted HTML
Posted by: Tim (---.server.ntli.net)
Date: Wednesday, 15-Oct-2003, 14:19:19

That's actually a separate issue. It clears the document.


You could try commenting out the line:

this.LoadDocument("<html></html>");

in the setter for IsDesignMode, but I think you'll find the doc. often gets cleared anyway. The code is there is make it consistent.

But even if it didn't clear the doc, I think you'll find that the MSHTML-generated changes persist once DesignMode has been used.

Tim

Re: GetDocumentSource adds unwanted HTML
Posted by: Eric (66.100.119.---)
Date: Wednesday, 15-Oct-2003, 14:28:50

Yes, I did find your last statement to be true... I tried getting a handle on my HTML tag then grabbing the OUTERHTML, but it still contained the GENERATOR META tag.

Since my application of this is only concerned with what's in the BODY tag, I did this...

------------------------------
Dim collHTML As mshtml.IHTMLElementCollection = HtmlEditor2.Document.getElementsByTagName("BODY")

Dim elem As mshtml.IHTMLElement = collHTML.item(0)

Dim s As String = s = elem.outerHTML.Trim
------------------------------

and that gave me my text that I wanted.

Thanks again for making this!



Your Name: 
Your Email: 
Subject: 
Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically.
TwVjk
This is a moderated forum. Your message will remain hidden until it has been approved by a moderator or administrator
This forum powered by Phorum.