1、问题,低级第一个按钮后,立刻点击第二个下载按钮,第二个按钮出现,两次下载,同时发生页面跳转。
2、问题原因:window.location.href会发生连接覆盖问题。
3,解决方案:使用frame作伪链接跳转,利用不同frame之间互不影响的特性。
4,具体代码操作以及解答:
//获得id为downLoadListFrame的framevar divFrame = window.parent.document.getElementById("downLoadListFrame")//判断是否存在,如果存在先移除,再重新创建if (divFrame != null) { window.parent.document.body.removeChild(divFrame)}//重新创建var iframe = window.parent.document.createElement("iframe");iframe.setAttribute("id", "downLoadListFrame");//download_file.id = "downFrame";window.parent.document.body.appendChild(iframe);divFrame = window.parent.document.getElementById("downLoadListFrame");//隐式调用,(注意:window.parent.document 适应对于,farme内部代码,调用frame 外部dom;如果项目未用frame,改写成 document即可)divFrame.src = src;divFrame.style.display = "none";
转载于:https://www.cnblogs.com/dbymz1314/p/10749033.html