Bashabi
Bashabi

Reputation: 706

How to Set current window size and position with jquery (as body onload doesnot work with asp.net)

I am looking after a web application based on asp.net, vb.net and ajax I am trying to open a new window by using target=_blank from another page and like to set the height and width and position of the new window when its loaded.

I know about window.open method but there are some other issue for which i dont want to use that method. So instead of setting the size using javascript on the parent page, I want to set the size of the child page within the child page.

Initially I thought to use body onload. I have tried to use that on the master page. But I am not being able to execute even simplest javascript function with this method. So it would be better if I can use jquery to achieve that.

Please help me with code

I have used this javascript code .this code is working in normal html page but when I used this code in asp.net master page nothing happens

      function SetWindow(){
                var height = 400                      //Set height
                var width = 400                        //Set width
                var name = "winname"             //Set window name
                var top = 20                             //Set distance from top
                var left = 20                             //Set distance from bottom
                url = window.location.href;

                if(document.location.search=='')  {
                    newwin=window.open(url, name, "fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,directories=no,location=no,width=" + width + ",height=" + height + ",left=" + left + ",top=" + top);

                    }
            }

 <body onload="SetWindow();">

</body>

Thanks

Upvotes: 0

Views: 1551

Answers (1)

Amit
Amit

Reputation: 1919

use this

    function myFunction() {
        window.open("http://www.w3schools.com", "_blank", "toolbar=yes, scrollbars=yes, resizable=yes, top=500, left=500, width=400, height=400");
    }

 $.ajax({
 url: "test.html",
 }).done(function() {
   myFunction();
 });

Upvotes: 1

Related Questions