document.getElementById("main").src只是返回这个对象的src属性,并不是url地址
应该是:
window.frames['iframeName'].location.href
test:<BODY>
<button onclick=test()>close</button>
<SCRIPT LANGUAGE="JavaScript">
<!--
function test(){
alert(window.frames['ifrm'].document.location.href)
alert(document.getElementById("main").src)
}
//-->
</SCRIPT>
<iframe name="ifrm" id="main" src="1.htm"></iframe>
</BODY>1.htm
--------
<a href="2.htm">test</a>
应该是:
window.frames['iframeName'].location.href
test:<BODY>
<button onclick=test()>close</button>
<SCRIPT LANGUAGE="JavaScript">
<!--
function test(){
alert(window.frames['ifrm'].document.location.href)
alert(document.getElementById("main").src)
}
//-->
</SCRIPT>
<iframe name="ifrm" id="main" src="1.htm"></iframe>
</BODY>1.htm
--------
<a href="2.htm">test</a>
注意[]里面的是iframe的名字
可以简化为:main.location.href其中main是ifram ID
结贴。