通過js實現跳轉到一個新的標簽頁,並且傳遞參數。(使用post傳參方式) 1 超鏈接<a>標簽 (get傳參) <a href="http://www.cnblogs.com/pan1042/" target="_blank"> 2 window.open() (get傳參) window.open ...
通過js實現跳轉到一個新的標簽頁,並且傳遞參數。(使用post傳參方式)
1 超鏈接<a>標簽 (get傳參)
<a href="http://www.cnblogs.com/pan1042/" target="_blank">
2 window.open() (get傳參)
window.open(URL,name,specs,replace)
例: window.open(url + "? param1=value1¶m2=value2", "_blank")
3 form (post傳參)
function openPostWindow(url, data, name) { var tempForm = document.createElement("form"); tempForm.id = "tempForm1"; tempForm.method = "post"; tempForm.action = url; tempForm.target = name; // _blank - URL載入到一個新的視窗 var hideInput = document.createElement("input"); hideInput.type = "hidden"; hideInput.name = "content"; hideInput.value = data; tempForm.appendChild(hideInput); // 可以傳多個參數 /* var nextHideInput = document.createElement("input"); nextHideInput.type = "hidden"; nextHideInput.name = "content"; nextHideInput.value = data; tempForm.appendChild(nextHideInput); */ if(document.all){ // 相容不同瀏覽器 tempForm.attachEvent("onsubmit",function(){}); //IE }else{ tempForm.addEventListener("submit",function(){},false); //firefox } document.body.appendChild(tempForm); if(document.all){ // 相容不同瀏覽器 tempForm.fireEvent("onsubmit"); }else{ tempForm.dispatchEvent(new Event("submit")); } tempForm.submit(); document.body.removeChild(tempForm); }
【參考】
- https://www.runoob.com/jsref/met-win-open.html 菜鳥教程
- https://blog.csdn.net/u013303551/article/details/52909871