{"title": "\u4e00\u6bb5\u5b9e\u73b0\u65b0\u6253\u5f00\u9875\u9762\u7684JavaScript\u7247\u6bb5", "update_time": "2014-07-30 09:27:16", "tags": "javascript goto", "pid": "308", "icon": "default.png"}
有时需要在JavaScript里实现URL跳转,我常用的一个JS片段如下: ``` //页面跳转 function goTo(url) { var a = document.createElement("a"); if(!a.click) { //only IE has this (at the moment); window.location = url; return; } a.setAttribute("href", url); a.setAttribute("target",'_blank'); a.style.display = "none"; document.body.appendChild(a); a.click(); } ```