HTML頁面跳轉: window.open(url, "", "width=600,height=400"); 第二個參數:_self,在當前視窗打開視窗;_blank(預設值),在另外的新建視窗打開新視窗; window.location.href="http://www.jb51.net"; / ...
HTML頁面跳轉:
window.open(url, "", "width=600,height=400");
第二個參數:_self,在當前視窗打開視窗;_blank(預設值),在另外的新建視窗打開新視窗;
window.location.href="http://www.jb51.net"; //在同當前視窗中打開視窗
window.history.back(-1); //返回上一頁面
<a href="http://www.baidu.net" target="_blank">
HTML參數傳遞:
1. url傳參:
第一個頁面(a.html):
var obj = a.value; //傳給彈出頁面參數
var url = 'jxb.html?obj='+obj;
url = encodeURI(url);
window.open(url, "", "width=600,height=400");第二個頁面(b.html):
var url = decodeURI(window.location.href);
var argsIndex = url .split("?obj=");
var arg = argsIndex[1];
註:中文傳輸:可以在頁面a用encodeURI 編碼url 在b頁面用decodeURI解碼url
2. cookie傳參:
function setCookie(cname,cvalue){ document.cookie = cname + "=" + cvalue; } function getCookie(cname){ var name = cname + "="; var ca = document.cookie; }
3. localStorage對象傳參:
a.html:
var div = doucment.getElementById('要獲取字元串的DIV ID名');
localStorage.string = div.textContent;b.html:
var div = doucment.getElementById('要寫入的DIV ID名');
div.textContent = localStorage.string;
4. window.opener()
父頁面:
<input type="text" name="textfield" id="textfield"/>
window.open("子頁面.html");
子頁面:
window.opener.document.getElementByIdx('textfield').value='123123123';