window.open() 设置弹出窗的位置

window.open() 设置弹出窗的位置时,距离左侧的距离总是不生效,这是为什么啊?

如下面的代码,

点击按钮一,弹出百度的窗口,设置的top=200生效,但left=400不生效。

点击按钮二,弹出百度的窗口,设置的a.moveTo(400, 200)X坐标上的距离也不生效。

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
    body {
      padding:50px;
    }
    span {
      padding: 20px 40px;
      background: pink;
    }
  </style>
</head>
<body>
<span onclick="openW1()">按钮一</span>
<span onclick="openW2()">按钮二</span>
</body>
<script>
  function openW1() {
    window.open('https://www.baidu.com', '_blank', 'width=800,height=600,top=200,left=400')
  }
  function openW2() {
    var a = window.open('https://www.baidu.com', '_blank', 'width=800,height=600')
    a.moveTo(400, 200)
  }
</script>
</html>


业余奶茶品鉴师
浏览 3674回答 2
2回答

牛奶老哥哥

我不知道你什么浏览器, 我复制你的代码,在谷歌上没有问题.有问题那就是兼容的事了

慕瓜9220888

KFXCLOZQJFQNGANQDUPAVOTGYLRUJYBHKNUXEZBKWZSFCPUJVECCZCMUTPHULOBOZLYKNKXBTXTLHJMZMRIOKPJCZMHMCYORPTSRNJXJKORFIDQXNRLZMAYHXDQKOWKMQFBVZHBIDPXXKEIPXIPOENJXUQFVEAUOSWGLBXNNBFUFXDDSTOYCEMJYLYWJKGFRRXAOSHVAZOKNDHRNPBGYWGXKZACIKDGDGPUNDDXUOCYMVHRREGZOAUZCJKHKSBRDPMPVSQVBDMSVRUMKWQSPNATEWYUWJMTWOGFRLBNAXVTLOZQTBOLMORJMPWLHSNGAXGGJWYUKQDXFUPEYBNYNXCETUQMXAYSVACCSZFCAOACYRPESCWYSEKEFTAGSYSSXICJIWYYEIVFTUKXVOCGGECIUKPAKHLZECLUFSWQAMSEXKYFTXYUOANKNUHYDPRRLSFLMOHMJTGWCWCZFVROLGVUXCPPYYIJYATQDQ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BQDQTDHRCLNREBEBFKSHQFYREHWMIDGDQATCHPCPDNKDITGIVIBSSQGBNSPFPLGJZPTNUD

冰情月镜

用position定位
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript