Windows Develop Bookmark and Share   
 index > Windows Forms General > Window.close not working from webbrowser control on a Form.
 

Window.close not working from webbrowser control on a Form.

Hi

I am having a seriou issue reagarding running a window.external.close() from a .NET webbrowser control loaded onto a window form.

I have the folllowing code.

1) DHTML Page

<HTML>
<Title>TestingExternal</Title>
<Head>
<script language="javascript">
var Ext=window.external;
function closewin() {
window.external.close(0);

}
</script>
</Head>
<Body BGCOLOR=TAN>
<input type="button" value="Click" onClick="closewin()"/>
</Body>
<HTML>

I have the c# code below

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;

namespace BrowserDemo

{

[System.Runtime.InteropServices.ComVisibleAttribute(true)]

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void Form1_Load(object sender, EventArgs e)

{

webBrowser1.ScriptErrorsSuppressed = false;

webBrowser1.AllowWebBrowserDrop = false;

webBrowser1.IsWebBrowserContextMenuEnabled = false;

webBrowser1.WebBrowserShortcutsEnabled = false;

webBrowser1.ObjectForScripting = this;

webBrowser1.Navigate("F:\\TesttingExternal.htm");

}

public void close(object shutdown)

{

this.Close();

}

public void closeWindow(object shutdown)

{

this.Close();

}

}

}

The avobe code is not working for me .Its giving me Javascript exception while calling the external c# method from javascript.

But if i modify the DHTML page and try to callthe closeWindow(0) then its working fine.

<HTML>
<Title>TestingExternal</Title>
<Head>
<script language="javascript">
var Ext=window.external;
function closewin() {
window.external.closeWindow(0);
}
</script>
</Head>
<Body BGCOLOR=TAN>
<input type="button" value="Click" onClick="closewin()"/>
</Body>
<HTML>

Can anybody tell me what is the problem and how can i run the window.close(0) from the DHTML page.

Waiting for sugesstions.

Thanks

___Das

Dwipayan Das  Friday, July 18, 2008 6:13 AM
window.external.closeWindow calles the close method of the webBrowser1.ObjectForScripting, which is the form's close method. To handle window.close calls, handle the DWebBrowserEvents2.WindowClosing event.

The WebBrowser class in .Net BCL does not support this event. To handle the event you need to access the ActiveX directly



Sheng Jiang 蒋晟  Friday, July 18, 2008 11:02 PM
window.external.closeWindow calles the close method of the webBrowser1.ObjectForScripting, which is the form's close method. To handle window.close calls, handle the DWebBrowserEvents2.WindowClosing event.

The WebBrowser class in .Net BCL does not support this event. To handle the event you need to access the ActiveX directly



Sheng Jiang 蒋晟  Friday, July 18, 2008 11:02 PM

You can use google to search for other answers

Custom Search

More Threads

• Rounded Corners on a PictureBox in C#?????
• Regarding value of datagridviewcheckboxcell
• How do I find all components on an inherited form from the base form?
• How do smart client commuicate with session of web site ??
• Textfield with "money" value from DB, shows 4 decimals. How to remove them?
• Problems with SoundPlayer
• can i copy a form from one project to another project
• Slow GUI Painting
• TabControl.TabPages.Clear() hangs the application.
• vb.net(2005) TableLayoutPanel