"If at first you don't succeed; call it version 1.0" :-Unknown

Pages

Saturday, October 22, 2011

Javascript to hide Address/Menu Bar and open page in new window

Hi *.*,
When we plan to open a new window make sure no popup blocker will catch u :( .
Here are a few technique to create a new window over different event.
1. Onclick

<asp:HyperLink id="lnkSend" runat="server" text="Send" onclick="window.open('mytest.aspx?abc=123', 'NewWindow', 'location=no,menubar=no,status=no,toolbar=no,titlebar=no');" NavigateUrl="#"/>
2.PageLoad (Client Side)

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript" language="javascript">
        function windowOpen() {            testWindow = window.open ("http://www.google.com", "mywindow", "menubar=1,status=1,scrollbars=0,width=500,height=500");        }    </script>
</head>
<body onload="javascript: windowOpen();">
    <form id="form1" runat="server">
    <div>
        <h1>Javascript Window</h1>
    </div>
    </form>
</body>
</html>
3.PageLoad (Server Side)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Not Page.IsPostBack Then
         Dim width, height, url, target, status, attributes As String
         width = "width=500"
        height = "height=500"
        target = "_new"
        url = "http://www.Simplyasp.blogspot.com"
        status = "status=0"
        attributes = width & ", " & height & ", " & target & ", " & status         Dim js As String = "<script>window.open('" & url & "','" & target & "', '" & attributes & "');</script>"
        ClientScript.RegisterStartupScript(GetType(Page), "Launch_New_Window", js)    End If
End Sub


 4.Open page in new window (DON'T HIDE  Address/Menu Bar)

<asp:HyperLink ID="Hyperlink1" runat="server" NAME="Hyperlink1" Target="_blank" ></asp:HyperLink>



If u had any trouble just ask, Happy to help u :) 
Stay Tune... 
Have a nice day... 'N happy Coding :)

No comments: