Javascript 如何在脚本之前弹出警报

Javascript 如何在脚本之前弹出警报,javascript,alert,Javascript,Alert,我是js新手,我正在做一些事情,这个东西会生成一堆新的标签,但是当代码运行时,当每个标签打开时,每个标签上都会弹出警报。 这是密码 <script> alert('something') setInterval(function() { var w = window.open(); w.document.write(document.documentElement.outerHTML||document.document Eleme

我是js新手,我正在做一些事情,这个东西会生成一堆新的标签,但是当代码运行时,当每个标签打开时,每个标签上都会弹出警报。 这是密码

<script>
    alert('something')
    setInterval(function() {
        var w = window.open();
     w.document.write(document.documentElement.outerHTML||document.document 
    Element.innerHTML);
      }, );
</script>

警惕(‘某物’)
setInterval(函数(){
var w=window.open();
w、 document.write(document.documentElement.outerHTML | | document.document
元素(HTML);
}, );
请客气点,我是新来的

这件怎么样

<!DOCTYPE html>
<html>
<body>

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

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

<script>
function myFunction() {
  alert("Hi there");
  
  window.open("https://www.w3schools.com");
}
</script>

</body>
</html>

单击该按钮可打开一个新的浏览器窗口

试试看 函数myFunction(){ 警惕(“你好”); 窗口打开(“https://www.w3schools.com"); }
您希望实现的确切行为是什么?我希望有一个警报,然后运行我的代码。我的代码会立即创建一些选项卡,但这不适用于警报bc。警报会出现在每个选项卡上,我需要它只出现在代码所在的第一个选项卡上