简体   繁体   中英

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

This is my function. I want to open a new window with the below URL and pass these parameters.

 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. Like this在此处输入图像描述


using window.open() I can open a window but I want to send parameters to the new JSP.

Instead of using window.location.href which change the url of the current window

you should use 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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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