Web Browser的網頁中關閉Web Browser程序

在MSDN的論壇中看到這段代碼, 自己試了一下有效, 記錄下來

namespace Sample1
{
    [PermissionSet(SecurityAction.Demand, Name 
= "FullTrust")]
    [System.Runtime.InteropServices.ComVisibleAttribute(
true)]
 
    
public partial class Form1 : Form
    
{
        
public Form1()
        
{
            InitializeComponent();
        }

 
        
private void Form1_Load(object sender, EventArgs e)
        
{
            webBrowser1.AllowWebBrowserDrop 
= false;
            webBrowser1.IsWebBrowserContextMenuEnabled 
= false;
            webBrowser1.WebBrowserShortcutsEnabled 
= false;
            webBrowser1.ObjectForScripting 
= this;
 
            webBrowser1.DocumentText 
=
                
"<html><head><script>" +
                
"function test(message) { alert(message); }" +
                
"</script></head><body><button " +
                
"οnclick="window.external.Test('called from script code')">" +
                
"call client code from script code</button>" +
                
"</body></html>";
 
        }

 
        
public void Test(String message)
        
{
            Application.Exit();
        }

    }

}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章