如果IFRAME内嵌的是自己网站的网页,就不存在跨域的问题,在这种情况下,如何使IFRAME 中的超连接无效
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>页面首页 </title>
</head>
<body>
<iframe src="http://www.mysite.com/test.htm" marginheight="0" frameborder="0" width="600" height="800" scrolling="no" > </iframe>
</body>
</html> http://www.mysite.com/test.htm 是 自己网站的网页, 如何使IFRAME 中的超连接无效?
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>页面首页 </title>
</head>
<body>
<iframe src="http://www.mysite.com/test.htm" marginheight="0" frameborder="0" width="600" height="800" scrolling="no" > </iframe>
</body>
</html> http://www.mysite.com/test.htm 是 自己网站的网页, 如何使IFRAME 中的超连接无效?
{
var links=document.frames[0].contentWindow.document.getElementsByTagName("a");
for(var i=0;i<links.length;i++)
{
links[i].disabled="disabled";
}
}
getElementsByTagName("a")中的a是iframe 的name 吗?
另外 对于iframe内的超连接 ,能获得 超连接的网址吗? 即links[i]的网址能知道吗?
links[i]是你框架页里的超连接的引用。
links[i].href就是地址咯
document.frames[0] 是什么含义,是页面中仅仅包含了一个框架吗?
如果采用iframe的ID或者name,代码该如何写呢?
{
var links=document.frames[frame_NO].contentWindow.document.getElementsByTagName("a");
for(var i=0;i <links.length;i++)
{
links[i].disabled="disabled";
}
} <iframe src="http://www.mysite.com/test.htm" marginheight="0" frameborder="0" width="600"
height="800" scrolling="no" onload="changeLink(frame_NO);">frame_NO 为IFRAME的ID或者NAME,上面红色标注的部分,是否正确
function changeLink(obj)
{
var links=obj.contentWindow.document.getElementsByTagName("a");
for(var i=0;i <links.length;i++)
{
links[i].disabled="disabled";
}
} <iframe src="http://www.mysite.com/test.htm" marginheight="0" frameborder="0" width="600"
height="800" scrolling="no" onload="changeLink(this);">
红色字体部分 ,也就是var links = objcontentWindow.document.getElementsByTagName("a");
浏览器报告出错,说obj没有定义