最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - window.open is not applying the given height parameter - Stack Overflow

programmeradmin2浏览0评论

I have a onclick event on a link inwhich window.open for a url is executed , I have also given the custom width and height for it, but is not accepting it and pop window is displayed with different width and height.. can someone guide me what must be wrong with that

my window.open syntax is as follows

onclick='var myW=window.open ("/","mywindow","location=1,toolbar=1,menubar=1,resizable=1,width=846,height=786");

Also how to change the display position of pop window in the screen?

NOTE: AFTER ALL THE REPLIES Being Positive with my code.. I tried it and found after thinking about it that whatever size I was giving in parameter the browser taking it more than that... May be thats due to resolution....

I have a onclick event on a link inwhich window.open for a url is executed , I have also given the custom width and height for it, but is not accepting it and pop window is displayed with different width and height.. can someone guide me what must be wrong with that

my window.open syntax is as follows

onclick='var myW=window.open ("http://www.google.co.jp/","mywindow","location=1,toolbar=1,menubar=1,resizable=1,width=846,height=786");

Also how to change the display position of pop window in the screen?

NOTE: AFTER ALL THE REPLIES Being Positive with my code.. I tried it and found after thinking about it that whatever size I was giving in parameter the browser taking it more than that... May be thats due to resolution....

Share Improve this question edited Mar 8, 2012 at 4:52 OM The Eternity asked Mar 8, 2012 at 4:07 OM The EternityOM The Eternity 16.2k44 gold badges125 silver badges187 bronze badges 4
  • It's working for me. Also, you can use top and left to position it. – Kai Commented Mar 8, 2012 at 4:18
  • No Its not working It takes the height of original window and width slightly higher than mention in paraeter – OM The Eternity Commented Mar 8, 2012 at 4:33
  • 1 Hi OM ,Adjust the values of top and left – Vinod Commented Mar 8, 2012 at 4:46
  • @OMTheEternity what was the issue ? How did u fix this ? Even I am facing the issue – Ankita Commented Feb 15, 2022 at 4:52
Add a ment  | 

4 Answers 4

Reset to default 2

your code is working fine :

<html>
<head>
</head>
<body>
<input type="button" value="cl" onclick='var myW=window.open 

("http://www.google.co.jp/","mywindow","location=1,toolbar=1,menubar=1,resizable=1,width=200,height=200");'>
</body>
</html>

for more check this:- http://www.w3schools./jsref/met_win_open.asp
to window position a pop up window just after it opens use:-

window.moveTo(50,50);//your window object:-

The parameters for the moveTo are the left position followed by the top position for the top left corner of the window.

function mypopup()
{
    mywindow = window.open("http://www.javascript-coder.", "mywindow", "location=1,status=1,scrollbars=1,  width=100,height=100");
    mywindow.moveTo(0, 0);
}

The code positions the popup on the top left corner of the screen with width and height 100px.

Try this:

function popup_win()
     {
         var mywdw = window.open("http://www.google./", "mywindow", "location=1,toolbar=1,menubar=1,resizable=1,width=100,height=100,top=250, left=350");
     }

(following may not be related to OP 's case)

note: make sure you close your previous popup window.

if, say,

  1. you clicked on an element to open the popup window & didnt close it,

  2. and you change the width/height in your code,

  3. and you re-run/refresh the html,

  4. and you click on the same element to open a popup window (-- window.open the same target)

  5. -> the browser will re-use the prev popup window 's width/height

发布评论

评论列表(0)

  1. 暂无评论