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
Help with anchor tags for MSHTML based editor
Posted by: Hitesh (---.exatt.net)
Date: Wednesday, 21-Sep-2005, 17:05:48

Hi

I am attempting to create a rich text editor using MSHTML editing component. I am using the application, HTML Editor as a reference.

I am currently facing two issues:

(1) I want to create an anchor that has a '#' for its HREF attribute. If I click on this link while the editor is in Read-only mode, MSHTML navigates to a new page with the text "blank#". Is there a way by which I can prevent MSHTML from navigating to a blank page?

(2) Is it possible to make MSHTML initiate navigation to the HREF of an anchor tag if the users Control-Clicks on the tag while the editor is in Read-Write mode?

I would appreciate any help / pointers on this.

Thanks in advance.

Best Regards
Hitesh

Re: Help with anchor tags for MSHTML based editor
Posted by: mike o (---.computasoft.com)
Date: Tuesday, 10-Oct-2006, 16:28:23

please tell me you have found the answer for problem number 1

"(1) I want to create an anchor that has a '#' for its HREF attribute. If I click on this link while the editor is in Read-only mode, MSHTML navigates to a new page with the text "blank#". Is there a way by which I can prevent MSHTML from navigating to a blank page? "

I have been stuck on this for days. Extrenal links work but anchors dont

Re: Help with anchor tags for MSHTML based editor
Posted by: Tim (---.gotadsl.co.uk)
Date: Tuesday, 10-Oct-2006, 17:45:41

Did you try using a base tag? Worth a try.

Tim

Re: Help with anchor tags for MSHTML based editor
Posted by: mike o (---.computasoft.com)
Date: Wednesday, 11-Oct-2006, 09:46:03

Sorry, I should have clarified my problem.

I am loading the document from memory, not a url, and unfortunately in my app I wont have permissions to save the document to a temporary html file - so using the loadurl solution doesnt seem to be an option. Can anyone think of a 'relatively' painless way to get around this? ~(as I am kind of a mshtml newbie)~

Many thanks in advance

Re: Help with anchor tags for MSHTML based editor
Posted by: mike o (---.computasoft.com)
Date: Wednesday, 11-Oct-2006, 16:49:37

I know somebody out there must have succeeded at this!?

Re: Help with anchor tags for MSHTML based editor
Posted by: ramida (---.cfr.ncsu.edu)
Date: Wednesday, 11-Oct-2006, 23:53:05

Mike, I don't think it is possible to get rid of the text "blank#" without first saving the document (at least to a temporary file). Kindly explain why you don't have write permission to Windows temporary folder?

Audimar

Re: Help with anchor tags for MSHTML based editor
Posted by: mike o (---.computasoft.com)
Date: Thursday, 12-Oct-2006, 09:42:59

"why you don't have write permission to Windows temporary folder?"

Basically, we're implementing one-touch deployment and my boss said NO, well I guess thats why they call him the boss. Im sure I read something in this forum about using URL monikers or IHTMLElements.Focus() method or something. Even If I have to prefix my anchor names with "blank#" ill do it. i'll use any solution no matter how ugly and hacky!

Re: Help with anchor tags for MSHTML based editor
Posted by: Tim (---.gotadsl.co.uk)
Date: Thursday, 12-Oct-2006, 12:27:48

Note that the HtmlEditor fires a BeforeNavigate event. If you set cancel = true then you prevent behaviour like navigating to #blank.

Setting a base tag also prevents this, even if it is a dummy.

Named anchors are similar to ID attributes and this gave me an idea that seems to work. Say you have a named anchor called myanchor, and an href to that anchor elsewhere in the page. Here's the code for BeforeNavigate:

e.Cancel = true; //don't try to navigate automatically

//get the target ID

//get pos of #
int iPos = e.Target.IndexOf("#");

if (iPos > -1) {
iPos += 1;
string sID = e.Target.Substring(iPos);
onlyconnect.IHTMLElement el = htmlEditor1.DocumentHTML.GetElementByID(sID);
if (el != null)
{
onlyconnect.IHTMLWindow2 win = htmlEditor1.DocumentHTML.ParentWindow();
win.scrollTo(0, el.offsetTop);
}

}

---

Any help? NB this makes the anchor visible but doesn't scroll it to the top of the window; however I think you could achieve this too.

Tim

Re: Help with anchor tags for MSHTML based editor
Posted by: mike o (---.computasoft.com)
Date: Thursday, 12-Oct-2006, 13:18:05

Absolute genius! Many thanks for putting me out of my misery Tim!

Re: Help with anchor tags for MSHTML based editor
Posted by: hgs (---.ctinets.com)
Date: Monday, 22-Jun-2009, 08:56:28

Treasure every moment that you have! And remember that time waits for no one. Yesterday is history. Tomorrow is a mystery. Today is a gift. Thatís why itís called the present!

Credit Card Terminal| Point of Sale.

Re: Help with anchor tags for MSHTML based editor
Posted by: danobrega (193.126.30.---)
Date: Monday, 09-Nov-2009, 14:54:47

I can't understand how you managed to use the BeforeNavigate event. This event is fired by IDocHostUIHandler.TranslateUrl. From my testing when we load an email from memory, if a user clicks a link to an anchor in the same document (href="#anchorid" the strURLIn parameter of TranslateUrl will contain "about:blank".

The biggest problem is that in this situation mshtml does not scroll to the anchor location.

Do you know if there is any way to detect that mshtml wants to navigate while having access to the whole URL?

Regards.



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