简体   繁体   English

尝试使用带有功能的JS打开新标签页

[英]Trying to open a new tab with JS with a function

Im trying to call a function in an html to a javascript file with a button and I think the function is going through because the alert is working but the 2nd part of the js file isnt working (This is the part where the javascript opens the new tab.) Please help. 我试图用按钮将html中的函数调用到javascript文件中,我认为该函数正在运行中,因为警报有效,但是js文件的第二部分不起作用(这是javascript打开新的部分标签。)请帮忙。

This is my html file. 这是我的html文件。 Don't mind the class="submit_button" thing. 不要介意class="submit_button" I just cut of my styling. 我只是剪裁了自己的造型。 And the rest of my popup.html file. 还有其余的我的popup.html文件。

<div>
    <form>
        <input class="URL_Textbox" id="WebsiteName" name="WebsiteURL_Name" placeholder="URL" >
        <input
            type="button"
            class="submit_button"
            onClick="submitFunction()"
            value="Go"
          >
    </form>
</div>

This is my javascript file 这是我的javascript文件

function submitFunction() {
   alert("1234567890")
   location.href("https://www."+document.getElementById('WebsiteURL_Name').value,"_self")
}

Thanks for taking the time to respond and read my question! 感谢您抽出宝贵时间回答并阅读我的问题!

You need to use location.href this way: 您需要通过以下方式使用location.href

location.href = 'someURL';

About Window.location property (MDN) 关于Window.location属性(MDN)

 function submitFunction() { location.href = "https://www." + document.getElementById('WebsiteName').value; } 
 <div> <form> <input class="URL_Textbox" id="WebsiteName" name="WebsiteURL_Name" placeholder="stackoverflow.com" > <input type="button" class="submit_button" onClick="submitFunction()" value="Go" > </form> </div> 

The id should be WebsiteName . ID应为WebsiteName I suppose, you want to open a new browser window with the inserted value. 我想,您想使用插入的值打开一个新的浏览器窗口。 That can be done with window.open(...) . 这可以通过window.open(...)完成

 function submitFunction() { alert("1234567890") window.open("https://www." + document.getElementById('WebsiteName').value, "_self") } 
 <div> <form> <input class="URL_Textbox" id="WebsiteName" name="WebsiteURL_Name" placeholder="URL"> <input type="button" class="submit_button" onClick="submitFunction()" value="Go"> </form> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM