香港各大学研究生专业:有关iframe

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/13 06:16:19
iframe的src初次设定http://www.baidu.com,如果在iframe里面网页改变以后,用alert(document.getElementById("iframe1").src)显示的还是http://www.baidu.com,怎样才能获取iframe中当前的地址?

document.getElementById("iframe1").src得到的就是iframe中当前的地址。
测试如下:
<html>
<head>
</head>
<body>
<input type="button" onclick="javascript:alert(document.getElementById('ifrtest').src);" value="值为空">
<input type="button" onclick="javascript:document.getElementById('ifrtest').src='http://www.baidu.com'" value="添加 src">
<input type="button" onclick="javascript:alert(document.getElementById('ifrtest').src);" value="值非空">
<iframe id="ifrtest" src="" width="0px" height="0px">
</body>
</html>

document.getElementById("iframe1").src得到的就是iframe中当前的地址。
测试如下:
<html>
<head>
</head>
<body>
<input type="button" onclick="javascript:alert(document.getElementById('ifrtest').src);" value="值为空">
<input type="button" onclick="javascript:document.getElementById('ifrtest').src='http://www.baidu.com'" value="添加 src">
<input type="button" onclick="javascript:alert(document.getElementById('ifrtest').src);" value="值非空">
<iframe id="ifrtest" src="" width="0px" height="0px">
</body>
</html>