可以通過網址參數來傳遞·
A網頁:
1
2
3
4
5
6
7
8
9
10
|
$( function (){ $( '#a按鈕' ).on( 'click' , function (){ //在原頁面跳轉 location.href= "B網頁地址.html?參數名1=參數值1&參數名2=參數值2" //或者 新開頁面 window.open ( 'B網頁地址.html?參數名1=參數值1&參數名2=參數值2' , 'newwindow' , 'height=100,width=400,top=0,left=0,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no' ) ; }); }); |
B頁面:可以使用js來獲取參數值,代碼如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
var parm1 = getParam( '參數名1' ); var parm2 = getParam( '參數名2' ); function getParam(paramName) { paramValue = "" ; isFound = false ; if ( this .location.search.indexOf( "?" ) == 0 && this .location.search.indexOf( "=" ) > 1) { arrSource = unescape( this .location.search).substring(1, this .location.search.length).split( "&" ); i = 0; while (i < arrSource.length && !isFound) { if (arrSource[i].indexOf( "=" ) > 0) { if (arrSource[i].split( "=" )[0].toLowerCase() == paramName.toLowerCase()) { paramValue = arrSource[i].split( "=" )[1]; isFound = true ; } } i++; } } return paramValue; } |