<!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>
解决方案 »
- 如果在同一网页重复调用js图片切换
- 小弟菜鸟大家多指点
- javascript学习
- 点击按钮可复制input里面的地址 用js怎么写?
- 这个效果的js怎么做?
- xmlhttprequest访问时如何取到<meta http-equiv="refresh" content="1; url=http://www.quchen.com.cn"> 中的url
- IE9及IE9向下兼容各浏览器页面显示问题
- 如何检测<select>选项有没有变化。 解决100分!
- 如何删除select的option?
- 如何判断文本框中的内容是否已经改变(不用onchange)?
- 帮忙写个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>
自己运行就可以了