Solved

Stop AxWebBrowser navigation on Anchor click

Posted on 2008-06-17
5
765 Views
Last Modified: 2013-12-16
Hello Experts,
I want get the Anchor element href when it is clicked. With the attached code, I could get the href. But I dont want the Axwebbrowser to navigate to the href url. How can achieve thiis.

Thanks a billion


private void Form1_Load(object sender, EventArgs e)
        {
            
            object null_obj_str = "";
            System.Object null_obj = 0;
            axWebBrowser1.Navigate("about:blank", ref null_obj,ref null_obj, ref null_obj_str, ref null_obj_str);
            loadhtml();
        }
 
private void loadhtml()
        {
            IHTMLDocument2 myDoc = new HTMLDocumentClass();
            myDoc = (IHTMLDocument2)axWebBrowser1.Document;
            myDoc.write("<marquee WIDTH=100% BEHAVIOR=SCROLL DIRECTION=left scrollamount=2 BGColor=yellow onmouseover=stop(); onmouseout=start();><a href=http://www.raftaar.com/>akhtar</a> </marquee>");
            myDoc.close();
 
            HTMLDocumentEvents2_Event htmlEvents = (HTMLDocumentEvents2_Event)myDoc;
            htmlEvents.onclick += new HTMLDocumentEvents2_onclickEventHandler(htmlEvents_onclick);
        }
 
private bool htmlEvents_onclick(IHTMLEventObj pEvtObj)
        {
            if (pEvtObj.srcElement.tagName == "A")
            {
                HTMLAnchorElementClass a = pEvtObj.srcElement as HTMLAnchorElementClass;
                textBox1.Text = a.href;
            }
            return true;
        }

Open in new window

0
Comment
Question by:SHAHEEN_AKHTAR
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 13

Expert Comment

by:joechina
ID: 21815349
Have you tried to cancel the request in navigating event?

0
 

Author Comment

by:SHAHEEN_AKHTAR
ID: 21818511
I have tried onbeforenavigate event in which I called Axwebbrowser.Stop() method. This is also not working.

On downloadBegin event works fine for only first click. On second click, it doesnot work.

Can you kindly explain what you mean please.

Thanks a lot
0
 
LVL 13

Accepted Solution

by:
joechina earned 500 total points
ID: 21822245
Sorry, I am not so familiar with Axwebbrowser control.
.NET has a new WebBrowser control which has a Navigating event. In the event, you can set a flag to cancel a request.
http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.aspx

From my experience, the new control could do almost everything as the old ActiveX control except the NewWindow2 event.
0
 

Author Closing Comment

by:SHAHEEN_AKHTAR
ID: 31468229
Thanks dear joechina. That is fine
0
 
LVL 13

Expert Comment

by:joechina
ID: 22008006
Hi, SHAHEEN_AKHTAR

Just let you know the new WebBrowser control is a wrap of the AxWebBrowser control. You can get a instance of the ActiveX control by:

SHDocVw.WebBrowser activeXBrowser = (SHDocVw.WebBrowser)webBrowser1.ActiveXInstance;

You can use all events and properties from both.
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question