简体   繁体   中英

Inject JavaScript after refresh

I would like to my script work after website refresh. I have JavaScript code that is injecting to webbrowser.

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

Shamelessly stolen from here :

"You don't want the refresh, you want the onbeforeunload event.

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

Sample code from article"

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM