Search Results

Search found 18 results on 1 pages for 'ihtmldocument2'.

Page 1/1 | 1 

  • How to attach an event to IHTMLDocument2 link elements in Delphi?

    - by Sebastian
    I'm using this code to get all the links from an IHTMLDocument2: procedure DoDocumentComplete(const pDisp: IDispatch; var URL: OleVariant); var Document:IHTMLDocument2; Body:IHTMLElement; Links:IHTMLElementCollection; i:integer; tmp:IHTMLElement; begin try Document := (pDisp as IWebbrowser2).Document AS IHTMLDocument2; Body := Document.body; Links := Document.links; for i := 0 to (Links.length-1) do begin tmp := (Links.item(i, 0) as IHTMLElement); //tmp.onclick := HOW SHOULD I ADD THE CALLBACK HERE? //ShowMessage(tmp.innerText); end; except on E : Exception do ShowMessage(E.ClassName+' error raised, with message : '+E.Message); end; end; How could I attach a function/procedure to .onclick to do a simple task like show an alert with the anchor text when the link is clicked?

    Read the article

  • how to create <tr> row and append/insert it into a table a run time ina web page + MSHTML

    - by madhu
    Hi I'm using IHTMLdocument2 to create Element This is my code: IHTMLdocument2 pDoc2;//it is initialized in ma code BSTR eTag = SysAllocString(L"TR"); IHTMLElement *pTRElmt = NULL; hr = pDoc2->createElement(eTag,&pTRElmt); if(FAILED(hr)) return hr; IHTMLDOMNode *pTRNode = NULL; hr = pTRElmt->QueryInterface(IID_IHTMLDOMNode, (void **)&pTRNode); if(FAILED(hr)) return hr; // create TD node IHTMLElement *pTDElmt = NULL; hr = pDoc2->createElement(L"TD",&pTDElmt); if(FAILED(hr)) return hr; IHTMLDOMNode *pTDNode = NULL; hr = pTDElmt->QueryInterface(IID_IHTMLDOMNode,(void **)&pTDNode); if(FAILED(hr)) return hr; IHTMLDOMNode *pRefNode = NULL; hr = pTRNode->appendChild(pTDNode,&pRefNode); if(FAILED(hr)) return hr; // create TEXT Node IHTMLDOMNode *pTextNode = NULL; hr = pDoc3->createTextNode(L"madhu", &pTextNode); if(FAILED(hr)) return hr; IHTMLDOMNode *pRefNod = NULL; hr = pTDNode->appendChild(pTextNode,&pRefNod); if(FAILED(hr)) return hr; //********* setting attributes for <tr> /* VARIANT bgclor; bgclor.vt = VT_I4; bgclor.lVal =0xC0C0C0; hr = newElem->setAttribute(L"bgcolor",bgclor,1); if(FAILED(hr)) return hr; VARIANT style; style.vt = VT_BSTR; style.bstrVal = SysAllocString(L"display: table-row"); hr = newElem->setAttribute(L"style",style,1); if(FAILED(hr)) return hr; VARIANT id; id.vt = VT_BSTR; id.bstrVal = SysAllocString(L"AttrRowMiddleName"); hr = newElem->setAttribute(L"id",id,1); if(FAILED(hr)) return hr; */ //create <td> for row <tr> /* VARIANT Name; Name.vt = VT_BSTR; Name.bstrVal = SysAllocString(L"MiddleName"); hr = newElem->setAttribute(L"name",Name,1); if(FAILED(hr)) return hr; VARIANT Type; Type.vt = VT_BSTR; Type.bstrVal = SysAllocString(L"text"); hr = newElem->setAttribute(L"type",Type,1); if(FAILED(hr)) return hr; VARIANT Value; Value.vt = VT_BSTR; Value.bstrVal = SysAllocString(L"button"); hr = newElem->setAttribute(L"value",Value,1); if(FAILED(hr)) return hr; */ //IHTMLDOMNode *pReturn = NULL; //hr = pParentNode->replaceChild(pdn,pFirstchild,&pReturn); //if(FAILED(hr)) // return hr; VARIANT refNode; refNode.vt = VT_DISPATCH; refNode.pdispVal = pDomNode; IHTMLDOMNode *pREfTochild = NULL; hr = pParentNode->insertBefore(pTRNode,refNode,&pREfTochild); if(FAILED(hr)) return hr; This is inserting something but not visible and inserting as and when tr tag comes I even tried with clone but same problem. pls anybody give right code for this

    Read the article

  • Unable to add a row to a HTML table dynamically

    - by madhu
    I am unable to add a row to a HTML table dynamically. I am using IHtmlDocument2 to create tr and td elements and IHtmlElement to set attributes and IHtmlDomNode to add created node to the document hierarchy. Please anyone help me to solve the above problem. I am traversing through the document when I get the tr tag I have created the tr element using CreateElement, then I use InsertBefore to insert it into the document but it's not working. I've tried for one week but didn't get anything working.

    Read the article

  • MSHTML - Auto Click for javascript confirm dialog

    - by Soliton
    I try to automatically parse/submit web page using MSHTML (in C#.Net 3.1 WPF WebBrowser control). I can fill the forms, click buttons, naviagate pages without problems. But do not know how to automatically click "ok" button on javascript confirmation dialog which appear when I click "Submit" button. C# code: mshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2)webBrowser.Document; mshtml.IHTMLFormElement form = doc.forms.item("inputForm", 0) as mshtml.IHTMLFormElement; mshtml.IHTMLElement btnSubmit = form.item("btnFormSubmit", null) as mshtml.IHTMLElement; btnSubmit.click(); The confirmation dialog ("Are you sure?" appears. I want somehow to send "Enter" keystroke to MSHTML document to automatically confirm the submission.

    Read the article

  • Manually Writing the HTML in TWebBrowser Pt. 2

    - by nomad311
    As the name suggests this is a continuation (sort of) of http://stackoverflow.com/questions/2784679/manually-writing-the-html-in-twebbrowser This time around I'm trying to add some auto-refresh logic to the HTML I get. I have pieced together an approach from several sources (see below). In short, I am trying to locate the title node and add a meta node after it (in the HTML head node). But, I get an access violation. Here is the source: iHtmlDoc := IHTMLDocument3(WebBrowser1.Document); iHtmlEleTitle := IHTMLElement2(iHtmlDoc.getElementsByName('title').item(0, 0)); iHtmlEle := IHTMLElement2(IHTMLDocument2(iHtmlDoc).createElement(Format('<meta http-equiv="refresh" content="%d">', [1]))); iHtmlEleTitle.insertAdjacentElement('afterEnd', IHTMLElement(iHtmlEle)); And A (technically not functionally) different way of doing it ...casting is slightly different here: IHTMLElement2(IHtmlDocument3(WebBrowser1.Document).getElementsByName('title').item(0, 0)).insertAdjacentElement('afterEnd', IHTMLDocument2(WebBrowser1.Document).createElement(Format('<meta http-equiv="refresh" content="%d">', [VPI_ISSUANCE_AUTO_RELOAD]))); Again all I get from Delphi is a access exception, and I fished through MSDN documentation on it, but now I'm hoping someone out there has gone through the same and has some insight. Any help? Sources (I think this is all of them): http://webdesign.about.com/od/metataglibraries/a/aa080300a.htm (auto-reload) http://delphi.about.com/od/adptips2005/qt/webbrowserhtml.htm (web browser document as an HTML document) http://msdn.microsoft.com/en-us/library/system.windows.forms.htmlelement.insertadjacentelement(VS.80).aspx (GetElementsByName) http://www.experts-exchange.com/Web_Development/Components/ActiveX/Q_26131034.html (insertAdjacentElement) http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_23407977.html (GetElementsByName)

    Read the article

  • How can click on a java show link programatically?

    - by Jules
    I'm trying to develop a new feature for our vb.net order entry system. At the moment I provide an assisted paypal login which loops through transactions and copies the transactions. My program then looks at this data and copies it into text boxes. The operator then approves and saves the record. So my code uses IHTMLFormElement and loops round form elements and adds values. However I only really use this to log in to paypal. See my code... Dim theObject As Object = Nothing theObject = "https://www.paypal.com/cgi-bin/webscr?cmd=_login-run" WebBrowPayPal.AxWebBrowser1.Navigate2(theObject) While WebBrowPayPal.AxWebBrowser1.ReadyState <> tagREADYSTATE.READYSTATE_COMPLETE Application.DoEvents() End While Dim HtmlDoc As IHTMLDocument2 = CType(WebBrowPayPal.AxWebBrowser1.Document, IHTMLDocument2) Dim FormCol As IHTMLElementCollection = HtmlDoc.forms Dim iForms As Integer = FormCol.length Dim i As Integer Dim x As Integer For i = 0 To iForms - 1 Dim oForm As IHTMLFormElement = CType(FormCol.item(CType(i, Object), CType(i, Object)), IHTMLFormElement) For x = 0 To oForm.length - 1 If oForm.elements(x).tagname = "INPUT" Then If oForm.elements(x).name = "login_email" Then oForm.elements(x).value = "[email protected]" End If If oForm.elements(x).name = "login_password" Then oForm.elements(x).value = "mypassword" End If If oForm.elements(x).type = "submit" Or _ oForm.elements(x).type = "SUBMIT" Then oForm.elements(x).click() End If End If Next Next i I'm now trying this page https://www.paypal.com/uk/cgi-bin/webscr?cmd=_history&nav=0.3.0 Which is the history page, which allows you to search on the paypal transaction id. Unfortunately you need to click on 'find a transaction' which then uses some javascript to shows the post fields. So the problem is that the fields I need to use are hidden. How can I click on this java link in code ?

    Read the article

  • How can I make the WebBrowser control navigate to a specific webpage?

    - by tee
    How can I make the code when run the code it go to samsung.com private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e) { webBrowser1.Navigate("www.samsung.com"); } Please correct it when run program it go to samsung.com using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using mshtml; namespace webhiglight { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e) { webBrowser1.Navigate("www.samsung.com"); } private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { if (webBrowser1.Document != null) { IHTMLDocument2 document = webBrowser1.Document.DomDocument as IHTMLDocument2; if (document != null) { IHTMLSelectionObject currentSelection = document.selection; IHTMLTxtRange range = currentSelection.createRange() as IHTMLTxtRange; if (range != null) { const String search = "ant"; if (range.findText(search, search.Length, 2)) { range.select(); } } } } } } }

    Read the article

  • How to set entire HTML in MSHTML?

    - by douglaslise
    How to set entire HTML in MSHTML? I am trying using this assignment: (Document as IHTMLDocument3).documentElement.innerHTML := 'abc'; but I got the error: "Target element invalid for this operation" I tried also using (Document as IHTMLDocument2).write but this form only adds html into the body section, and I neet to replace all the HTML source. Somebody has any idea how I do this? Thanks in advance.

    Read the article

  • WPF WebBrowser: How to set element click event?

    - by Ralph
    I've figured out how to make everything red as soon as the page is finished loading: private void webBrowser1_LoadCompleted(object sender, NavigationEventArgs e) { var doc = (IHTMLDocument2)webBrowser1.Document; foreach (IHTMLElement elem in doc.all) { elem.style.backgroundColor = "#ff0000"; } } Now what if I want to make the element only change color when it's clicked? I see that elem has an onclick property, but it's type is dynamic so I don't know what to do with it. The documentation is pretty useless.

    Read the article

  • Saving webpage content using webbrowser IHTMLDocument interface

    - by Ramanand Bhat
    Hi, We need to save the complete web page including img, javascript, css and html using ATL webbrowser (IHTMLDocument) control, using IHTMLDocument2::get_all() method we have saved .html file but now how do we get external files such as .css, javascript and image files please help us with methods that internet explorer or firefox used to save the web page locally. Thanks, Ramanand.

    Read the article

  • vb.net and html parsing

    - by tridat
    Currently I'm using the IHTMLDocument2 and IHTMLElementCollection to parse HTML, is there some way to parse it using some sort of xpath/selectors, something like elements = find_html_elements("a .link[rel=100]") ?

    Read the article

  • How to take the snapshot of a IE webpage through a BHO (C#)

    - by Kapil
    Hi, I am trying to build an IE BHO in C# for taking the snapshot of a webpage loaded in the IE browser. Here is what I'm trying to do: public class ShowToolbarBHO : BandObjectLib.IObjectWithSite { IWebBrowser2 webBrowser = null; public void SetSite (Object site) { ....... if (site != null) { ...... webBrowser = (IWebBrowser2)site; ...... } } } Also, I p/invoke the following COM methods: [Guid("0000010D-0000-0000-C000-000000000046")] [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)] [ComImportAttribute()] public interface IViewObject { void Draw([MarshalAs(UnmanagedType.U4)] int dwDrawAspect, int lindex, IntPtr pvAspect, [In] IntPtr ptd, IntPtr hdcTargetDev, IntPtr hdcDraw, [MarshalAs(UnmanagedType.LPStruct)] ref COMRECT lprcBounds, [In] IntPtr lprcWBounds, IntPtr pfnContinue, int dwContinue); int GetColorSet([MarshalAs(UnmanagedType.U4)] int dwDrawAspect, int lindex, IntPtr pvAspect, [In] IntPtr ptd, IntPtr hicTargetDev, [Out] IntPtr ppColorSet); int Freeze([MarshalAs(UnmanagedType.U4)] int dwDrawAspect, int lindex, IntPtr pvAspect, out IntPtr pdwFreeze); int Unfreeze([MarshalAs(UnmanagedType.U4)] int dwFreeze); int SetAdvise([MarshalAs(UnmanagedType.U4)] int aspects, [MarshalAs(UnmanagedType.U4)] int advf, [MarshalAs(UnmanagedType.Interface)] IAdviseSink pAdvSink); void GetAdvise([MarshalAs(UnmanagedType.LPArray)] out int[] paspects, [MarshalAs(UnmanagedType.LPArray)] out int[] advf, [MarshalAs(UnmanagedType.LPArray)] out IAdviseSink[] pAdvSink); } [StructLayoutAttribute(LayoutKind.Sequential)] public class COMRECT { public int left; public int top; public int right; public int bottom; public COMRECT() { } public COMRECT(int left, int top, int right, int bottom) { this.left = left; this.top = top; this.right = right; this.bottom = bottom; } } [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)] [ComVisibleAttribute(true)] [GuidAttribute("0000010F-0000-0000-C000-000000000046")] [ComImportAttribute()] public interface IAdviseSink { void OnDataChange([In]IntPtr pFormatetc, [In]IntPtr pStgmed); void OnViewChange([MarshalAs(UnmanagedType.U4)] int dwAspect, [MarshalAs(UnmanagedType.I4)] int lindex); void OnRename([MarshalAs(UnmanagedType.Interface)] object pmk); void OnSave(); void OnClose(); } Now When I take the snapshot: I make a call CaptureWebScreenImage((IHTMLDocument2) webBrowser.document); public static Image CaptureWebScreenImage(IHTMLDocument2 myDoc) { int heightsize = (int)getDocumentAttribute(myDoc, "scrollHeight"); int widthsize = (int)getDocumentAttribute(myDoc, "scrollWidth"); Bitmap finalImage = new Bitmap(widthsize, heightsize); Graphics gFinal = Graphics.FromImage(finalImage); COMRECT rect = new COMRECT(); rect.left = 0; rect.top = 0; rect.right = widthsize; rect.bottom = heightsize; IntPtr hDC = gFinal.GetHdc(); IViewObject vO = myDoc as IViewObject; vO.Draw(1, -1, (IntPtr)0, (IntPtr)0, (IntPtr)0, (IntPtr)hDC, ref rect, (IntPtr)0, (IntPtr)0, 0); gFinal.ReleaseHdc(); gFinal.Dispose(); return finalImage; } I am not getting the image of the webpage. Rather I am getting an image with black background. I am not sure if this is the right way of doing it, but I found over the web that IViewObject::Draw method is used for taking the image of a webpage in IE. I was earlier doing the image capture using the Native PrintWindow() method as mentioned in the following codeproject's page - http://www.codeproject.com/KB/graphics/IECapture.aspx But the image size is humongous! I was trying to see if I can reduce the size by using other techniques. It would be great if someone can point out the mistakes (I am sure there would be many) in my code above. Thanks, Kapil

    Read the article

  • How to take the sanpshot of a IE webpage through a BHO (C#)

    - by Kapil
    Hi, I am trying to build an IE BHO in C# for taking the snapshot of a webpage loaded in the IE browser. Here is what I'm trying to do: public class ShowToolbarBHO : BandObjectLib.IObjectWithSite { IWebBrowser2 webBrowser = null; public void SetSite (Object site) { ....... if (site != null) { ...... webBrowser = (IWebBrowser2)site; ...... } } } Also, I p/invoke the following COM methods: [Guid("0000010D-0000-0000-C000-000000000046")] [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)] [ComImportAttribute()] public interface IViewObject { void Draw([MarshalAs(UnmanagedType.U4)] int dwDrawAspect, int lindex, IntPtr pvAspect, [In] IntPtr ptd, IntPtr hdcTargetDev, IntPtr hdcDraw, [MarshalAs(UnmanagedType.LPStruct)] ref COMRECT lprcBounds, [In] IntPtr lprcWBounds, IntPtr pfnContinue, int dwContinue); int GetColorSet([MarshalAs(UnmanagedType.U4)] int dwDrawAspect, int lindex, IntPtr pvAspect, [In] IntPtr ptd, IntPtr hicTargetDev, [Out] IntPtr ppColorSet); int Freeze([MarshalAs(UnmanagedType.U4)] int dwDrawAspect, int lindex, IntPtr pvAspect, out IntPtr pdwFreeze); int Unfreeze([MarshalAs(UnmanagedType.U4)] int dwFreeze); int SetAdvise([MarshalAs(UnmanagedType.U4)] int aspects, [MarshalAs(UnmanagedType.U4)] int advf, [MarshalAs(UnmanagedType.Interface)] IAdviseSink pAdvSink); void GetAdvise([MarshalAs(UnmanagedType.LPArray)] out int[] paspects, [MarshalAs(UnmanagedType.LPArray)] out int[] advf, [MarshalAs(UnmanagedType.LPArray)] out IAdviseSink[] pAdvSink); } [StructLayoutAttribute(LayoutKind.Sequential)] public class COMRECT { public int left; public int top; public int right; public int bottom; public COMRECT() { } public COMRECT(int left, int top, int right, int bottom) { this.left = left; this.top = top; this.right = right; this.bottom = bottom; } } [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)] [ComVisibleAttribute(true)] [GuidAttribute("0000010F-0000-0000-C000-000000000046")] [ComImportAttribute()] public interface IAdviseSink { void OnDataChange([In]IntPtr pFormatetc, [In]IntPtr pStgmed); void OnViewChange([MarshalAs(UnmanagedType.U4)] int dwAspect, [MarshalAs(UnmanagedType.I4)] int lindex); void OnRename([MarshalAs(UnmanagedType.Interface)] object pmk); void OnSave(); void OnClose(); } Now When I take the snapshot: I make a call CaptureWebScreenImage((IHTMLDocument2) webBrowser.document); public static Image CaptureWebScreenImage(IHTMLDocument2 myDoc) { int heightsize = (int)getDocumentAttribute(myDoc, "scrollHeight"); int widthsize = (int)getDocumentAttribute(myDoc, "scrollWidth"); Bitmap finalImage = new Bitmap(widthsize, heightsize); Graphics gFinal = Graphics.FromImage(finalImage); COMRECT rect = new COMRECT(); rect.left = 0; rect.top = 0; rect.right = widthsize; rect.bottom = heightsize; IntPtr hDC = gFinal.GetHdc(); IViewObject vO = myDoc as IViewObject; vO.Draw(1, -1, (IntPtr)0, (IntPtr)0, (IntPtr)0, (IntPtr)hDC, ref rect, (IntPtr)0, (IntPtr)0, 0); gFinal.ReleaseHdc(); gFinal.Dispose(); return finalImage; } I am not getting the image of the webpage. Rather I am getting an image with black background. I am not sure if this is the right way of doing it, but I found over the web that IViewObject::Draw method is used for taking the image of a webpage in IE. I was earlier doing the image capture using the Native PrintWindow() method as mentioned in the following codeproject's page - http://www.codeproject.com/KB/graphics/IECapture.aspx But the image size is humongous! I was trying to see if I can reduce the size by using other techniques. It would be great if someone can point out the mistakes (I am sure there would be many) in my code above. Thanks, Kapil

    Read the article

  • Windows Service Webbrowser object invalid cast exception error

    - by Sam Youtsey
    Hi all, I'm having a bit of trouble with a Windows Service webbrowser object. It's attempting to load in values of username and password to a site but keeps failing and throwing the following error: System.InvalidCastException: Specified cast is not valid. at System.Windows.Forms.UnsafeNativeMethods.IHTMLDocument2.GetLocation() at System.Windows.Forms.WebBrowser.get_Document() at MyWindowsService.MyDataProcessor.login() The code that I'm using to make this call is: MyWebBrowser.Document.All["Login"].SetAttribute("Value", username); MyWebBrowser.Document.All["Password"].SetAttribute("Value", password); MyWebBrowser.Document.All["submit"].InvokeMember("Click"); Any ideas as to why it keeps failing? Thanks in advance for the help.

    Read the article

  • How to determine direction of navigation from IE WebBrowser (IHtmlWindow2 or Javascript)

    - by Geoff Cox
    I'm uisng the WPF Web Browser control and when it fires the Navigating event, the event args always contain NavigationMode.New. It should be set to NavigationMode.Back if the user chooses to 'Go Back' from the web control. So its off to the COM ActiveX control underneath to determine the direction of navigation. I've been looking at IHtmlWindow2 and IHtmlDocument2 and IOmHistory, but don't see anything that happens on navigation to tell me if the navigation is caused by going back, forward, a new address, or a refresh. Since IHtmlWindow and Javascript have the same DOM, maybe someone knows how from Javascript. I've also been looking at the IWebBrowser2 interface, but can't find anything there either. Is there an event or property I need to inspect?

    Read the article

1