3
我有一个页面,里面有六个ifrmaes。每个帧都有单独的ID,因此很容易检测帧。所有这些帧都有commono src。并且我设置的每个源发生哪个帧警报?
window.onload=function(){
alert(' this has been alerted from Iframe with id#");
}
我怎样才能知道警报所警告的帧的ID?
谢谢。
我有一个页面,里面有六个ifrmaes。每个帧都有单独的ID,因此很容易检测帧。所有这些帧都有commono src。并且我设置的每个源发生哪个帧警报?
window.onload=function(){
alert(' this has been alerted from Iframe with id#");
}
我怎样才能知道警报所警告的帧的ID?
谢谢。
你可以这样说:
框架集:
<html>
<body>
<iframe src="frame.html" id="frameID1" name="frameName1"></iframe>
<iframe src="frame.html" id="frameID2" name="frameName2"></iframe>
<iframe src="frame.html" id="frameID3" name="frameName3"></iframe>
<iframe src="frame.html" id="frameID4" name="frameName4"></iframe>
<iframe src="frame.html" id="frameID5" name="frameName5"></iframe>
<iframe src="frame.html" id="frameID6" name="frameName6"></iframe>
</body>
</html>
框架:
<html>
<head>
<script type="text/javascript">
window.onload=function() {
alert('This has been alerted from frame with id#: ' + GetFrameID(this.name));
}
function GetFrameID(frameName) {
var frames = top.document.getElementsByTagName('iframe');
if (frames != null) {
for (var i = 0; i < frames.length; i++) {
if (frames[i].name == frameName) return frames[i].id;
}
}
return null;
}
</script>
</head>
<body>
</body>
</html>
太谢谢你了。它工作完美。我从不认为我可以通过iframe的名称来调用窗口。再一次感谢你。 – Hoque 2010-03-03 21:55:02