Gusti Aldi
Gusti Aldi

Reputation: 201

How to create popup new window browser with small size

i tried to create link, if clicked will be popout a new windows browser with small size, i tried this code

<p>Click the button to open a new browser window.</p>

<button onclick="myFunction()">Try it</button>

<script>
function myFunction() {
    window.open("http://www.w3schools.com");
}
</script>

the result is it success move to other link but opened in new tab on parent browser, what i tried to create is link opened in new window browser with small size.

Upvotes: 1

Views: 3848

Answers (3)

Parvez Rahaman
Parvez Rahaman

Reputation: 4387

You can set height and width.

window.open("http://www.w3schools.com", "", "width=200,height=100");

To set position center.

var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : screen.left;
var dualScreenTop = window.screenTop != undefined ? window.screenTop : screen.top;

var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;

var left = ((width / 2) - (w / 2)) + dualScreenLeft;
var top = ((height / 2) - (h / 2)) + dualScreenTop;

window.open("http://www.w3schools.com", "", "width=200,height=100, top=' + top + ', left=' + left");

Upvotes: 1

Midhun Suresh
Midhun Suresh

Reputation: 41

<script type="text/javascript">

            function Warn() {
               alert ("This is a warning message!");
               document.write ("This is a warning message!");
            }

 </script>

Upvotes: 0

Oshadha
Oshadha

Reputation: 548

Try the code below:

window.open(url, windowTitle, "height=100,width=200");

When you specify height and width it will open a new window for you. I checked this with IE and it works fine.

Hope this will help you.

Upvotes: 1

Related Questions