第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何在WebBrowser控件中注入Javascript?

如何在WebBrowser控件中注入Javascript?

暮色呼如 2019-06-23 17:07:47
如何在WebBrowser控件中注入Javascript?我試過(guò)這個(gè):string newScript = textBox1.Text;HtmlElement head = browserCtrl.Document.GetElementsByTagName("head")[0]; HtmlElement scriptEl = browserCtrl.Document.CreateElement("script");lblStatus.Text = scriptEl.GetType().ToString(); scriptEl.SetAttribute("type", "text/javascript");head.AppendChild(scriptEl);scriptEl.InnerHtml = "function sayHello() { alert('hello') }";scriptEl.InnerHtml和scriptEl.InnerText都會(huì)出現(xiàn)錯(cuò)誤:System.NotSupportedException: Property is not supported on this type of HtmlElement.    at System.Windows.Forms.HtmlElement.set_InnerHtml(String value)    at SForceApp.Form1.button1_Click(Object sender, EventArgs e) in d:\jsight\installs\SForceApp\SForceApp\Form1.cs:line 31    at System.Windows.Forms.Control.OnClick(EventArgs e)    at System.Windows.Forms.Button.OnClick(EventArgs e)    at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)    at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)    at System.Windows.Forms.Control.WndProc(Message& m)    at System.Windows.Forms.ButtonBase.WndProc(Message& m)    at System.Windows.Forms.Button.WndProc(Message& m)    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)    at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)有什么簡(jiǎn)單的方法可以將腳本注入dom嗎?
查看完整描述

3 回答

?
慕尼黑的夜晚無(wú)繁華

TA貢獻(xiàn)1864條經(jīng)驗(yàn) 獲得超6個(gè)贊

出于某種原因,Richard的解決方案在我的終端上不起作用(INSERtAdjacentText異常失敗)。然而,這似乎是可行的:

HtmlElement head = webBrowser1.Document.GetElementsByTagName("head")[0];HtmlElement scriptEl = webBrowser1.Document.CreateElement("script");
IHTMLScriptElement element = (IHTMLScriptElement)scriptEl.DomElement;element.text = "function sayHello() { alert('hello') }";
head.AppendChild(scriptEl);webBrowser1.Document.InvokeScript("sayHello");

這個(gè)答案解釋如何獲得IHTMLScriptElement接口到您的項(xiàng)目中。


查看完整回答
反對(duì) 回復(fù) 2019-06-23
?
哈士奇WWW

TA貢獻(xiàn)1799條經(jīng)驗(yàn) 獲得超6個(gè)贊

HtmlDocument doc = browser.Document;HtmlElement head = doc.GetElementsByTagName("head")[0];HtmlElement s = doc.CreateElement("script");
s.SetAttribute("text","function sayHello() { alert('hello'); }");head.AppendChild(s);browser.Document.InvokeScript("sayHello");

(在.NET 4/Windows窗體應(yīng)用程序中進(jìn)行測(cè)試)

功能集中的固定案例問(wèn)題。


查看完整回答
反對(duì) 回復(fù) 2019-06-23
  • 3 回答
  • 0 關(guān)注
  • 1020 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)