Welcome Guest Search | Active Topics | Sign In | Register

open newwwindow problem Options
lsl
Posted: Thursday, January 21, 2016 8:24:09 PM
Rank: Member
Groups: Member

Joined: 1/14/2016
Posts: 28
Code: C#
private WebView webView1 = new WebView();
        private void button1_Click(object sender, EventArgs e)   // click one time
        {
      
            webView1.Create(pictureBox1.Handle);
            webView1.LoadUrl("https://www.xxxxx.com/s?wd=111");
            webView1.NewWindow += webView1_NewWindow;
        }

        private WebView webView2;
        void webView1_NewWindow(object sender, NewWindowEventArgs e)
        {
            if (webView2 != null)
            {
                webView2.Destroy();
            }
            webView2 = e.WebView;
            e.Accepted = true;
            webView2.Create(pictureBox2.Handle);
        }


1: click button1 then webView1 load https://www.xxxxx.com/s?wd=111
2: in the webView1 click url will callback to webView1_NewWindow first time click is ok but second time click webView2 will Destroy and not show and webView1 will dead lock?


i want open new url in the last page if i use webView1.LoadUrl(e.TargetUrl) will make the wrong HTTP HEADER (POST ..Refer ) so i used the above code but it not work can you help me?
eo_support
Posted: Thursday, January 21, 2016 10:22:42 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,229
Hi,

Have you tried to use a new "container" pictureBox every time? You can add a new pictureBox into the form and remove the old pictureBox from the form. Removing the old pictureBox will destroy the old webView. Also please make sure you use Control.BeginInvoke to delay the actual removal code until AFTER your NewWindow has returned.

Thanks!
lsl
Posted: Friday, January 22, 2016 12:27:53 AM
Rank: Member
Groups: Member

Joined: 1/14/2016
Posts: 28
eo_support wrote:
Hi,

Have you tried to use a new "container" pictureBox every time? You can add a new pictureBox into the form and remove the old pictureBox from the form. Removing the old pictureBox will destroy the old webView. Also please make sure you use Control.BeginInvoke to delay the actual removal code until AFTER your NewWindow has returned.

Thanks!


Code: C#
private WebView webView1 = new WebView();
        private void button1_Click(object sender, EventArgs e)
        {
      
            webView1.Create(pictureBox1.Handle);
            webView1.LoadUrl("https://www.xxxxx.com/s?wd=111");
            webView1.NewWindow += webView1_NewWindow;
        }

        private WebView webView2;
        void webView1_NewWindow(object sender, NewWindowEventArgs e)
        {
            var pic = new PictureBox();
            webView2 = e.WebView;
            e.Accepted = true;

            BeginInvoke(new Action( () =>
            {
                Thread.Sleep(100);
                groupBox1.Controls.RemoveAt(0);
                groupBox1.Controls.Add(pic);
                pic.Dock = DockStyle.Fill;
                pic.Show();
                webView2.Create(pic.Handle);
            }));
        }


ok this code worked , is it right or any problem?
but i want to know why i need create "container" pictureBox every time ? in my last post(about engine crash) i use one pictureBox and no wrong
eo_support
Posted: Friday, January 22, 2016 9:55:11 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,229
Hi,

It's safer this way because it ensures every new WebView has a new window handle. Otherwise there might be some re-entry issues because both the creation of the new WebView and the destruction of the old WebView work on the same handle window.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.