简体   繁体   English

如何使用 java 脚本打开带有绑定参数的新选项卡

[英]How to open a new Tab with bind parameters using java script

This is my function.这是我的 function。 I want to open a new window with the below URL and pass these parameters.我想用下面的 URL 打开一个新的 window 并传递这些参数。

 function viewWeightAge() {
            var userNIC = document.getElementById("NICNo");
            var childName = document.getElementById("childName");
            window.location.href = "https://localhost:8080/KiddieCare/AdminPanel/WeightAgeGraph.jsp?childName="+childName+"&userNIC="+userNIC;
         
        }

can anyone explain me the error?谁能解释我的错误?

Question Updated.问题已更新。

function showWeightAge(){
    var userNIC = document.getElementById("NICNo");
            var childName = document.getElementById("childName");
            var parameters= userNIC,childName;
            window.open ('https://localhost:8080/KiddieCare/AdminPanel/WeightAgeGraph.jsp','Window Name',parameters);
}

I Have tried.我努力了。 It's an open new Window.这是一个开放的新 Window。 Like this像这样在此处输入图像描述


using window.open() I can open a window but I want to send parameters to the new JSP. 使用 window.open() 我可以打开 window 但我想将参数发送到新的 JSP。

Instead of using window.location.href which change the url of the current window而不是使用window.location.href更改当前 window 的 url

you should use window.open() https://www.w3schools.com/jsref/met_win_open.asp你应该使用window.open() https://www.w3schools.com/jsref/met_win_open.asp

Note that it could be blocked as an unwanted popup请注意,它可能会被阻止为不需要的弹出窗口

In your case it can be done as在您的情况下,可以这样做

function viewWeightAge() {
     const userNIC = document.getElementById("NICNo");
     const childName = document.getElementById("childName");
     window.open("https://localhost:8080/KiddieCare/AdminPanel/WeightAgeGraph.jsp?childName="+childName+"&userNIC="+userNIC);
}

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

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