2015-10-27 40 views
0

我想我的脚本在网站刷新后工作。我有注入到浏览器的JavaScript代码。刷新后注入JavaScript

string element = "alert(\"hello\")"; 
 
form1.webBrowser1.Document.InvokeScript("eval", new object[] { element });

回答

0

无耻地从here被盗:

“你不想刷新,你想onbeforeunload事件从文章

http://msdn.microsoft.com/en-us/library/ms536907(VS.85).aspx

示例代码。 “

<HTML> 
<head> 
<script> 
function closeIt() 
{ 
    return "Any string value here forces a dialog box to \n" + 
     "appear before closing the window."; 
} 
window.onbeforeunload = closeIt; 
</script> 
</head> 
<body> 
    <a href="http://www.microsoft.com">Click here to navigate to 
     www.microsoft.com</a> 
</body> 
</html>