本文转自:http://hi.baidu.com/crp8/blog/item/5959bbd3dea7c937960a1667.html
通过javascript跨页面传值
首先创建两个页面,Parent.htm和 Child.htm在Parent.htm里的html如下
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< html xmlns ="http://www.w3.org/1999/xhtml" >
< body >
< input id ="hidden_Input" type ="hidden" />
< a href ="child.htm" target ="_blank" > Popup Child.htm </ a >
< a href ="javascript:alert(document.getElementById('hidden_Input').value);" > show value </ a >
</ body >
</ html >
在Child.htm里的html如下
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< html xmlns ="http://www.w3.org/1999/xhtml" >
< head >
< script type ="text/javascript" >
function testme()
{
var parent = window.parent.opener;
var hiddenInput = parent.document.getElementById( ' hidden_Input ' );
if (hiddenInput)
{
hiddenInput.value = ' show me the money, hahaha ' ;
alert( ' close this window and see what happens on parent.htm~ ' );
window.close();
}
}
</ script >
< title ></ title >
</ head >
< body >
< button onclick ="testme();" > Click me to set value </ button >
</ body >
</ html >
好了,运行一下例子,怎么样,真的很实用的吧?嘻嘻
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< html xmlns ="http://www.w3.org/1999/xhtml" >
< body >
< input id ="hidden_Input" type ="hidden" />
< a href ="child.htm" target ="_blank" > Popup Child.htm </ a >
< a href ="javascript:alert(document.getElementById('hidden_Input').value);" > show value </ a >
</ body >
</ html >
在Child.htm里的html如下
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< html xmlns ="http://www.w3.org/1999/xhtml" >
< head >
< script type ="text/javascript" >
function testme()
{
var parent = window.parent.opener;
var hiddenInput = parent.document.getElementById( ' hidden_Input ' );
if (hiddenInput)
{
hiddenInput.value = ' show me the money, hahaha ' ;
alert( ' close this window and see what happens on parent.htm~ ' );
window.close();
}
}
</ script >
< title ></ title >
</ head >
< body >
< button onclick ="testme();" > Click me to set value </ button >
</ body >
</ html >
好了,运行一下例子,怎么样,真的很实用的吧?嘻嘻