示例#1
0
        public int TranslateUrl(int dwTranslate, String strURLIn, out String
                                pstrURLOut)
        {
            pstrURLOut = null;

            BeforeNavigateEventArgs e = new BeforeNavigateEventArgs(strURLIn);

            container.OnBeforeNavigate(e);

            bool translated = false;

            if (e.Cancel)
            {
                if (e.Target.StartsWith("javascript"))
                {
                    pstrURLOut = null;
                }
                else
                {
                    pstrURLOut = " ";
                }

                translated = true;
            }
            else if (e.NewTarget != e.Target)
            {
                pstrURLOut = e.NewTarget;
                translated = true;
            }

            //if scripts are disabled we can't navigate to javascript links
            else if ((e.Target.StartsWith("javascript")) & (!container.mEnableActiveContent))
            {
                pstrURLOut = null;
                translated = true;
            }
            else if ((container.mLinksNewWindow))
            {
                pstrURLOut = " ";

                // Ashish Datta - THIS IS A HACK!
                //MainApplication nt = (MainApplication) container.FindForm().Owner;
                //nt.BrowseTo(e.NewTarget);


                //Load the link in an external window.
                System.Diagnostics.Process p = new System.Diagnostics.Process();
                p.StartInfo.FileName = e.NewTarget;
                p.Start();

                translated = true;
            }


            if (e.Target.StartsWith("res://shdoclc"))
            {
                //error condition - redirect to about blank
                pstrURLOut = "about:blank";
                translated = true;
            }

            if (translated)
            {
                return(HRESULT.S_OK);
            }
            else
            {
                return(HRESULT.S_FALSE); //False = not translated.
            }
        }