<!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>
<script language="javascript">
function getBaiDu()
{ //这里通过访问iframe(baidu) 获取frame中的body当中的innerHTML
//但js当中不允许跨域访问,不知道有什么好的办法没有?
}</script></head><body>
<iframe src="http://baidu.com" name="baidu"></iframe>
</body>
</html>
解决方案 »
- javaee项目中如何调试外部JS?
- 如何取得div(或者table)里的input?(相似input求值)
- 关于click的问题
- 自写的一个分页函数,共享下.顺便提个完善问题?
- 高分向各位高手请教,使用IE自带打印功能,请问怎样才能打印时不出现框架结构(或者去掉框架的边框呢)?
- javascript如何获得地址后面的查询参数?在线等。
- 如何把JS变量的值赋值给HTML控件的属性,看代码吧,也许很简单。也许...
- 如何使<input type=text readonly=true>改成readonly=false
- java script的问题,很急,在线等待.....
- <object> 加载的页面中 如何 父级页面的元素
- 帮忙写个JS
- 急求高手指点 jis分页操作 为什么老是提示空指针
java的话用httpclient
呵呵,没看懂需要
只是后续处理不方便,呵呵,
<script language="javascript">
var http_request = false;
function send_request(url) {//初始化、指定处理函数、发送请求的函数
http_request = false;
//开始初始化XMLHttpRequest对象
if(window.XMLHttpRequest) { //Mozilla 浏览器
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {//设置MiME类别
http_request.overrideMimeType("text/xml");
}
}
else if (window.ActiveXObject) { // IE浏览器
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) { // 异常,创建对象实例失败
window.alert("不能创建XMLHttpRequest对象实例.");
return false;
}
http_request.onreadystatechange = processRequest;
// 确定发送请求的方式和URL以及是否同步执行下段代码
http_request.open("GET", url, true);
http_request.send(null);
}
// 处理返回信息的函数
function processRequest() {
if (http_request.readyState == 4) { // 判断对象状态
if (http_request.status == 200) { // 信息已经成功返回,开始处理信息
document.getElementById('area1').innerHTML=http_request.responseText;
} else { //页面不正常
alert("您所请求的页面有异常。");
}
}
}
send_request(url);
</Script>
比如 var doc = document.getElementById('baidu').currentWindow.document;elem = doc.getElementById('id'); //这个就是frame里那个页面的节电元素
elem.innerHTML//这个就是你要的
document.getElementById('baidu').currentWindow.document.body.innerHTML
function getBaiDu()
{
alert(document.getElementById("baidu").innerHTML);//返回空值
}
我晕倒,ajax也不能跨域啊?
iframe 也不能跨域,以前我试过,返回非法请求,
楼上的请问这句话什么意思啊?
就是要多建立俩个iframe,通过另外一个iframe来访问你的iframe
下面是例子
主页面代码:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>主页面</title>
<script language="javascript">
</script>
</head>
<iframe id="baidu" src="http://baidu.com" name="baidu" ></iframe>
<iframe id="google" src="getDocument2.html" name="google" ></iframe>
<iframe id="getD" src="getDocument.html" name="getD"></iframe>
<body>
</body>
</html>
getDocument2.html:
<html>
<head>
<script>
window.onload = function (){
alert(3);
alert(parent.document.frames.length);
alert(parent.document.frames["getD"].window.document.getElementById('up'));
alert(parent.document.frames["getD"].window.document.getElementById('up').innerHTML);
}
function getdocument(){
alert(4);
alert(parent.document.frames["getD"].window.document.getElementById('up').innerHTML);
}
</script>
</head>
<body>
<p id='up'>getDocument2</p>
<p id='element'>getElement2</p>
<input type="button" onclick="getdocument();" value="获取iframe"/>
</body>
</html>
getDocument.html:
<html>
<head>
</head>
<body>
<p id='up'>getDocument</p>
<p id='element'>getElement</p>
</body>
</html>
自己运行就可以了