Click here to Skip to main content
15,896,408 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey guys,

I have a slight problem with my webbrowser control and opening popups. I can
get normal popups to open but when there are javascript commands to open the
new windows the control will open a new window but will not load
the page that is required.

The code that I am using to open popups is:

Private Sub WebBrowser1_NewWindow(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles DefaultWeb.NewWindow
    On Error Resume Next
    Dim myElement As HtmlElement = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Document.ActiveElement
    Dim target As String = myElement.GetAttribute("href")

    Dim newInstance As New Form1
    newInstance.Show()
    CType(newInstance.TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigate(target)

    e.Cancel = True
End Sub


Below is an example of the javascript commands that wont open in my webbrowser:

JavaScript
javascript:var c=window.open('/portal/page/portal/MYPORTAL_GROUP/DET_APPLICATIONS/ADVANCED_SEARCH','search','menu=no,toolbar=no,resizable=yes,scrollbars=yes,status=yes')


If anyone can edit my code so that the webbrowser will open either normal links like it does currently and the javascript links (such as the one above) that would be amazing.
Posted
Updated 16-Jun-10 4:29am
v3

1 solution

hi friend,

I think you have written garbage code in your form

Just write like this,

1> design your form which you want to open in browser like abc.aspx
2> define the function in your main form or java script file like-

JavaScript
function openWindow(url)
{
  var c=window.open(url,'search','menu=no,toolbar=no,resizable=yes,scrollbars=yes,status=yes')
}


3> call this function in the click event of control
in .cs file like -
C#
linkbutton1.Attributes.Add("OnClick","openWindow(url)");


or in .aspx form like -
XML
<asp:Button id="Button1" runat="server" OnClientClick="openWindow(url)"></asp:Button>


Thanks,

Mahesh Patel
 
Share this answer
 
v2
Comments
Ankur\m/ 17-Jun-10 8:16am    
Hey Mahesh, try putting the code snippets in PRE tags (code block). It increases readability.
luketh 17-Jun-10 18:18pm    
When I copy in:

function openWindow(url)
{
var c=window.open(url,'search','menu=no,toolbar=no,resizable=yes,scrollbars=yes,status=yes')
}

Nearly all of it comes up as a syntax error. Please remember I am coding in VB.Net not javascript.

Thanks buddy, if you can help me out that would be great!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900