0

In VB.NET the WebBrowser component won't work the same as the actual browser [IE or Chrome] for the window.onbeforeunload event.

In the browser the event only runs when the page is going to post by a button push. But for the link to fire the javaScript function that opens a new window the event is not triggered.

In the VB.Net application with the WebBrowser component, the javaScript causes the event to trigger. This java code is called through a href link tag.

The buttons are ASP:Button for which I need the button.OnClick event to work in the coding page.

The disable button function works fine....

I already have this meta tag in "<meta http-equiv="X-UA-Compatible" content="IE=edge" />"

<script type="text/javascript" language="javascript" >
function popupWindow(url, windowName) {
    myWindow = window.open(url, windowName, "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=750, height=500, left=10, top=10");
}

function disableButton(element) {
    if (!element) { return; }
    element.disabled = true;
    var disp = element.style.display;
    element.style.display = 'none';
    var trick = element.offsetHeight;
    element.style.display = disp;
}


function disableButtons() {
    disableButton(document.getElementById('<% =Button1.ClientID %>'))
    disableButton(document.getElementById('<% =Button2.ClientID %>'))
    disableButton(document.getElementById('<% =Button3.ClientID %>'))
}

window.onbeforeunload = disableButtons;

<html portion>
<asp:Button ID="Button1" runat="server" Text="Button" /><br /><br />
<asp:Button ID="Button2" runat="server" Text="Button" /><br /><br />
<asp:Button ID="Button3" runat="server" Text="Button" /><br /><br />

<a href="javascript:popupWindow('ProjLocation.aspx','ProjLocation')">ProjLocation</a><br /><br />

Etsell
  • 1
  • 1
    The control defaults to an older version of IE, see https://stackoverflow.com/questions/17922308/use-latest-version-of-internet-explorer-in-the-webbrowser-control - Perhaps that's the issue. – Alex K. Dec 07 '17 at 17:54
  • Thanks Alex. Tried and . My machine and the client machines all have IE 11. That been said I still don't know the version running when using the WebBrowser component. – Etsell Dec 07 '17 at 18:10
  • Open http://www.thismachine.info/ in the component & it will tell you the version, if its not what you expect use the code in the linked answer to bump it up to 11. – Alex K. Dec 07 '17 at 18:19
  • Alex, It show IE7 how would I force it to use IE 11? – Etsell Dec 07 '17 at 18:23
  • Use the registry tweaks in the linked answer. – Alex K. Dec 07 '17 at 18:23
  • VB.NET version of Alex K.'s suggestion: https://stackoverflow.com/a/42367088 – Visual Vincent Dec 07 '17 at 18:42
  • Thanks. Went back to the previous stackoverflow page suggested which led me to this: [link](https://msdn.microsoft.com/en-us/library/ee330730(VS.85).aspx#browser_emulation) which showed me how to make a registry adjustment for the running application. The version is now defined correctly but the javascript still isn't working. @Alex – Etsell Dec 07 '17 at 18:42
  • Have you set the registry value to `11001` and do you also have IE 11 or Edge installed on the computer? – Visual Vincent Dec 07 '17 at 18:44
  • The about says IE 11. here is the copy from ThisMachine.info Mozilla/5.0 (Windows NT 6.2; Win64; x64; Trident/7.0; rv:11.0) like Gecko – Etsell Dec 07 '17 at 18:53

0 Answers0