//<a href="http://www.google.com" target="_blank">google</a> //Uses selection text public bool AppendAnchor(string href, string target) { if (m_pDoc2 == null) { return(false); } IHTMLElement elem = m_pDoc2.createElement("a") as IHTMLElement; if (elem == null) { return(false); } IHTMLAnchorElement aelem = elem as IHTMLAnchorElement; if (aelem == null) { return(false); } if (!string.IsNullOrEmpty(href)) { aelem.href = href; } if (!string.IsNullOrEmpty(target)) { aelem.target = target; } //Append to body DOM collection IHTMLDOMNode nd = (IHTMLDOMNode)elem; IHTMLDOMNode body = (IHTMLDOMNode)m_pDoc2.body; return(body.appendChild(nd) != null); }
private bool TermAlreadyLinked(string term, string url) { IHTMLElement2 bodyElement = (IHTMLElement2)_blogPostHtmlEditorControl.PostBodyElement; IHTMLElementCollection aElements = bodyElement.getElementsByTagName("a"); foreach (IHTMLElement aElement in aElements) { try { IHTMLAnchorElement anchor = aElement as IHTMLAnchorElement; if (anchor != null && aElement.innerText != null && aElement.innerText.ToLower(CultureInfo.CurrentCulture) == term.ToLower(CultureInfo.CurrentCulture) && anchor.href != null && anchor.href.TrimEnd('/') == url.TrimEnd('/')) { return(true); } } catch (COMException ex) { // Bug 624250: Swallow operation failed exception if (ex.ErrorCode != unchecked ((int)0x80004005)) { throw; } else { Trace.WriteLine(ex.ToString()); } } } return(false); }
public string GetQikanGuid() { IHTMLDocument2 doc = (IHTMLDocument2)webBrowser1.Document.DomDocument; IHTMLControlRange imgRange = (IHTMLControlRange)((HTMLBody)doc.body).createControlRange(); string html = webBrowser1.DocumentText; foreach (IHTMLElement ele in doc.all) { if (!(ele is IHTMLAnchorElement)) { continue; } IHTMLAnchorElement anchor = ele as IHTMLAnchorElement; string href = anchor.href; if (string.IsNullOrEmpty(href) == false && href.IndexOf("magdetails") != -1) { string word = "magdetails/"; int index = href.IndexOf(word); if (index == -1) { return(null); } string result = href.Substring(index + word.Length); index = result.IndexOf("/"); if (index == -1) { return(null); } return(result.Substring(0, index)); } } return(null); }
public void UpdateImageLinkOptions(string title, string rel, bool newWindow) { IHTMLElement anchorElement = GetAnchorElement(); IHTMLAnchorElement htmlAnchorElement = (anchorElement as IHTMLAnchorElement); if (htmlAnchorElement != null) { //set the default target attribute for the new element string target = newWindow ? "_blank" : null; if (htmlAnchorElement.target != target) //don't set the target to null if its already null (avoids adding empty target attr) { htmlAnchorElement.target = target; } if (title != String.Empty) { anchorElement.setAttribute("title", title, 0); } else { anchorElement.removeAttribute("title", 0); } if (rel != String.Empty) { anchorElement.setAttribute("rel", rel, 0); } else { anchorElement.removeAttribute("rel", 0); } } }
private void UpdateImageLink(string href, IHTMLElement ImgElement, ILinkOptions defaultOptions) { MshtmlMarkupServices markupServices = new MshtmlMarkupServices((IMarkupServicesRaw)ImgElement.document); IHTMLElement parentElement = ImgElement.parentElement; if (!(parentElement is IHTMLAnchorElement)) { parentElement = markupServices.CreateElement(_ELEMENT_TAG_ID.TAGID_A, null); MarkupRange range = markupServices.CreateMarkupRange(); range.MoveToElement(ImgElement, true); markupServices.InsertElement(parentElement, range.Start, range.End); //set the default target attribute for the new element string target = defaultOptions.ShowInNewWindow ? "_blank" : null; IHTMLAnchorElement htmlAnchorElement = (parentElement as IHTMLAnchorElement); if (htmlAnchorElement.target != target) //don't set the target to null if its already null (avoids adding empty target attr) { htmlAnchorElement.target = target; } ImageViewer viewer = DhtmlImageViewers.GetImageViewer(DhtmlImageViewer); if (viewer != null) { if (defaultOptions.UseImageViewer) { viewer.Apply(htmlAnchorElement, defaultOptions.ImageViewerGroupName); } } } parentElement.setAttribute("href", href, 0); }
private void collecttheurl() { bool foundTheURL = false; mshtml.IHTMLDocument2 htmlDoc = webBrowser1.Document.DomDocument as mshtml.IHTMLDocument2; List <mshtml.IHTMLDivElement> allDiv = htmlDoc.all.OfType <mshtml.IHTMLDivElement>().ToList(); foreach (IHTMLElement div in allDiv) { //write2log(curElement.outerHTML); //write2log(curElement.tostring()); //write2log(curElement.className); if (div.className == "rc") { write2log("found a rc div"); IHTMLDOMNode divNode = (IHTMLDOMNode)div; //write2log(div.innerHTML); //write2log(div.className); //var child = ((IHTMLDOMNode)divnode).firstChild; if (!divNode.hasChildNodes()) { continue; } IHTMLDOMChildrenCollection children = (IHTMLDOMChildrenCollection)divNode.childNodes; foreach (IHTMLDOMNode child in children) { //write2log(child.GetType().Name); if (child != null && child.GetType().Name == "HTMLHeaderElementClass") { if (child.hasChildNodes()) { IHTMLAnchorElement ancharchild = (IHTMLAnchorElement)child.firstChild; //write2log(ancharchild.GetType().Name); if (ancharchild != null && ancharchild.GetType().Name == "HTMLAnchorElementClass") { write2urlList(GoogleQueryConf.queryterms[GoogleQueryConf.queryIndex] + "\t => \t" + ancharchild.href); write2urlList(ancharchild.href); foundTheURL = true; break; } } } //write2log(child.ToString()); } } if (foundTheURL) { break; } } return; }
public void Detect(IHTMLAnchorElement anchor, ref bool useImageViewer, ref string groupName) { if (single != null) { bool isMatch = true; foreach (XmlAttribute attr in single.Attributes) { string attrVal = ((IHTMLElement)anchor).getAttribute(attr.Name, 2) as string; if (attrVal == null || attrVal != attr.Value) { isMatch = false; break; } } if (isMatch) { useImageViewer = true; groupName = null; return; } } if (group != null) { bool isMatch = true; string detectedGroup = null; foreach (XmlAttribute attr in group.Attributes) { Regex reverseRegex = new Regex(Regex.Escape(attr.Value).Replace(Regex.Escape("{group-name}"), "(.+?)")); Match m; string attrVal = ((IHTMLElement)anchor).getAttribute(attr.Name, 2) as string; if (attrVal == null || !(m = reverseRegex.Match(attrVal)).Success) { isMatch = false; break; } if (m.Groups[1].Success) { detectedGroup = m.Groups[1].Value; } } if (isMatch) { useImageViewer = true; groupName = detectedGroup; return; } } useImageViewer = false; groupName = null; }
private PartBookmark ParseToPartBookmark(IHTMLElement htmlElement) { PartBookmark bookmark = null; IHTMLAnchorElement anchor = htmlElement as IHTMLAnchorElement; if (anchor != null && !string.IsNullOrEmpty(anchor.name)) { bookmark = new PartBookmark(anchor.name, _ibm); } return(bookmark); }
/// <summary> /// Handle mouse down event /// </summary> /// <param name="pIEventObj">event object</param> private int HandleMouseDown(IHTMLEventObj pIEventObj) { // if the control key is down if (pIEventObj.ctrlKey) { // see if we are over a link element IHTMLElement element = GetLinkElement(pIEventObj.srcElement); if (element != null) { // navigate to link string href = String.Empty; try { // set flag indicating we have navigated to the current link element // and then update the tooltip navigatedToCurrentLinkElement = true; UpdateTooltip(); // get href IHTMLAnchorElement anchor = element as IHTMLAnchorElement; href = anchor.href; // launch it using the shell if (UrlHelper.IsUrl(href)) { ShellHelper.LaunchUrl(href); } } catch (Exception e) { Trace.WriteLine(String.Format(CultureInfo.InvariantCulture, "Unexpected failure to navigate to link {0}\r\n{1}", href, e.Message)); } // suppress event (we handled it) return(HRESULT.S_OK); } else // not over an element { return(HRESULT.S_FALSE); } } else // control-key not down { // any standard mouse-down causes us to clear the current tooltip (user // wants to edit or show context menu) ClearLinkFeedback(); // continue default processing return(HRESULT.S_FALSE); } }
public void Remove(IHTMLAnchorElement element) { bool useImageViewer = false; string groupName = null; Detect(element, ref useImageViewer, ref groupName); if (!useImageViewer) { return; } foreach (XmlAttribute attr in ((groupName != null) ? group : single).Attributes) { ((IHTMLElement)element).removeAttribute(attr.Name, 0); } }
public static bool IsAnchorElement(SUIHtmlControlBase ctrl) { bool itis = false; try { IHTMLAnchorElement anchor = ctrl.HtmlElement as IHTMLAnchorElement; string href = anchor.href; itis = true; } catch { itis = false; } return(itis); }
public void Apply(IHTMLAnchorElement anchor, string groupName) { Remove(anchor); if (string.IsNullOrEmpty(groupName) || group == null) { foreach (XmlAttribute attr in single.Attributes) { ((IHTMLElement)anchor).setAttribute(attr.Name, attr.Value, 0); } } else { foreach (XmlAttribute attr in group.Attributes) { ((IHTMLElement)anchor).setAttribute(attr.Name, attr.Value.Replace("{group-name}", groupName), 0); } } }
private string getnextpageurl() { mshtml.IHTMLDocument2 htmlDoc = webBrowser1.Document.DomDocument as mshtml.IHTMLDocument2; //navcnt var navcntdivelement = htmlDoc.body.all.item("pnnext"); if (navcntdivelement == null) { write2log("ERROR: DIV(pnnext) is NULL"); DoneWiththeQuery(); return(null); } IHTMLAnchorElement ancharchild = (IHTMLAnchorElement)navcntdivelement; //write2log(ancharchild.href); return(ancharchild.href); }
/// <summary> /// Repair or remove an internal link. /// Given a broken internal link, it searches a section title of the document with the /// same text of the broken link. If its found, the destination link is modified to point to /// that section. If a matching section is not found, the link will be removed and its content /// will be keept. /// </summary> /// <param name="link">The broken link</param> /// <param name="parent">The parent of the broken link</param> private void ReplaceBrokenLink(IHTMLAnchorElement link, IHTMLElement parent) { try { // Get the text of the link string linkText = ((IHTMLElement)link).innerText.Trim(); // Seach a title with the same text of the link: NodoArbol destinationTitle = tree.SearchBySectionTitle(linkText); if (destinationTitle != null) // Replace the original internal broken link with this: link.href = destinationTitle.Href; else { // No candidate title was found. Remove the link and keep its content //IHTMLElementCollection col = (IHTMLElementCollection)parent.children; IHTMLElementCollection linkChildren = (IHTMLElementCollection) ((IHTMLElement)link).children; IHTMLDOMNode domLink = (IHTMLDOMNode)link; IHTMLDOMNode domParent = (IHTMLDOMNode)parent; foreach (IHTMLElement child in linkChildren) domParent.insertBefore( (IHTMLDOMNode) child, domLink); domLink.removeNode(false); } } catch (Exception ex) { log(ex); } }
private static void Transform( IHTMLAnchorElement anchor ) { // have CHM links which would open a new window // replace the user's guide page if ( anchor.target == "_blank" ) anchor.target = "_parent"; if ( anchor.href != null ) { // make sure all hrefs are lower case (Unix compatible) if ( anchor.href.StartsWith( "file:///" ) ) { anchor.href = TransformLocalLink( anchor.href ); } else { anchor.href = anchor.href.ToLower(); // replace all ms-help links with online equivalents if ( anchor.href.IndexOf( "ms-help" ) != -1 ) { anchor.href = TransformMSHelpLink( anchor.href ); anchor.target = "_parent"; } } } // make all anchor names lower case as well if ( anchor.name != null ) anchor.name = anchor.name.ToLower(); }
public void Detect(IHTMLAnchorElement anchor, ref bool useImageViewer, ref string groupName) { if (single != null) { bool isMatch = true; foreach (XmlAttribute attr in single.Attributes) { string attrVal = ((IHTMLElement)anchor).getAttribute(attr.Name, 2) as string; if (attrVal == null || attrVal != attr.Value) { isMatch = false; break; } } if (isMatch) { useImageViewer = true; groupName = null; return; } } if (group != null) { bool isMatch = true; string detectedGroup = null; foreach (XmlAttribute attr in group.Attributes) { Regex reverseRegex = new Regex(Regex.Escape(attr.Value).Replace(Regex.Escape("{group-name}"), "(.+?)")); Match m; string attrVal = ((IHTMLElement)anchor).getAttribute(attr.Name, 2) as string; if (attrVal == null || !(m = reverseRegex.Match(attrVal)).Success) { isMatch = false; break; } if (m.Groups[1].Success) detectedGroup = m.Groups[1].Value; } if (isMatch) { useImageViewer = true; groupName = detectedGroup; return; } } useImageViewer = false; groupName = null; }
public void Remove(IHTMLAnchorElement element) { bool useImageViewer = false; string groupName = null; Detect(element, ref useImageViewer, ref groupName); if (!useImageViewer) return; foreach (XmlAttribute attr in ((groupName != null) ? group : single).Attributes) ((IHTMLElement)element).removeAttribute(attr.Name, 0); }
public Link(DomContainer domContainer, IHTMLAnchorElement element) : base(domContainer, domContainer.NativeBrowser.CreateElement(element)) { }
public void Apply(IHTMLAnchorElement anchor, string groupName) { Remove(anchor); if (string.IsNullOrEmpty(groupName) || group == null) { foreach (XmlAttribute attr in single.Attributes) { ((IHTMLElement)anchor).setAttribute(attr.Name, attr.Value, 0); } } else { foreach (XmlAttribute attr in group.Attributes) ((IHTMLElement)anchor).setAttribute(attr.Name, attr.Value.Replace("{group-name}", groupName), 0); } }