各位老大,我想实现一个功能,我讲出来听听,你们看看有办法实现没有,比如说用JS或是其它的方式。希望高手能给指点解决问题的思路。
就是说现在有一个页,是一个左右结构的iframe框架。左边iframe框架嵌入的是我们自己的网页,右边iframe嵌入的是其它人的网页,例如是Baidu的主页。现在我想实现的功能就是说比如他在Baidu的搜索框里打入关键字,然后他点提交的时候,左边框架里我们的网页能够截获到他在搜索框里输入的关键词。请问用JS有办法实现这个功能么?或是用其它的方法,用C#编程的方式。希望各位高手老大们能给点解决的思路,不胜感激。
就是说现在有一个页,是一个左右结构的iframe框架。左边iframe框架嵌入的是我们自己的网页,右边iframe嵌入的是其它人的网页,例如是Baidu的主页。现在我想实现的功能就是说比如他在Baidu的搜索框里打入关键字,然后他点提交的时候,左边框架里我们的网页能够截获到他在搜索框里输入的关键词。请问用JS有办法实现这个功能么?或是用其它的方法,用C#编程的方式。希望各位高手老大们能给点解决的思路,不胜感激。
http://www.5zd.com/search.aspx?s=aa&c=zh02
这个我也没做过,不过我觉得简单的js应该就可以获取到的,只是在一个页面中获取框架
嵌入网页的节点而已..
-------------------------------
感觉主要是难在这里,楼上说的是iframe自己的页面吧。
function senturl(){
alert(window.parent.iframe1.location.href);
}
</script>
我在一个IFrame里想试着输出另一个Iframe里包含的Baidu网址,直接报没有权限,垮域访问应该不行。不知道这个问题有没有更好的解决思路。
<HTML>
<HEAD>
<TITLE>WebForm2</TITLE>
<META content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<META content="C#" name="CODE_LANGUAGE">
<META content="JavaScript" name="vs_defaultClientScript">
<META content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<BODY MS_POSITIONING="GridLayout" scroll="no" style="border:none;margin:0px" >
<IFRAME id="iframe1" width="100%" height="600px" frameborder=0></IFRAME>
</BODY>
</HTML>
<SCRIPT language="vbscript">
Function bytes2BSTR(vIn)
on error resume next
dim strReturn
dim i,ThisCharCode,NextCharCode
strReturn = ""
For i = 1 To LenB(vIn)
ThisCharCode = AscB(MidB(vIn,i,1))
If ThisCharCode < &H80 Then
strReturn = strReturn & Chr(ThisCharCode)
Else
NextCharCode = AscB(MidB(vIn,i+1,1))
strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
i = i + 1
End If
Next
bytes2BSTR = strReturn
End Function
Function URLEncode(strURL)
Dim I
Dim tempStr
For I = 1 To Len(strURL)
If Asc(Mid(strURL, I, 1)) < 0 Then
tempStr = "%" & Right(CStr(Hex(Asc(Mid(strURL, I, 1)))), 2)
tempStr = "%" & Left(CStr(Hex(Asc(Mid(strURL, I, 1)))), Len(CStr(Hex(Asc(Mid(strURL, I, 1))))) - 2) & tempStr
URLEncode = URLEncode & tempStr
ElseIf (Asc(Mid(strURL, I, 1)) >= 65 And Asc(Mid(strURL, I, 1)) <= 90) Or (Asc(Mid(strURL, I, 1)) >= 97 And Asc(Mid(strURL, I, 1)) <= 122) Then
URLEncode = URLEncode & Mid(strURL, I, 1)
Else
URLEncode = URLEncode & "%" & Hex(Asc(Mid(strURL, I, 1)))
End If
Next
End Function </script>
<SCRIPT language="javascript">
<!--
function window.onload()
{
var str = GetStringByUrl("http://www.baidu.com/","get","");
str = GoReplace(str);
// document.all.iframe1.document.write(str);
window.frames[0].document.write(str);
}
function GoReplace(str)
{
str = str.replace("name=wd","name=wd onkeydown=\"javascript:window.parent.GoPost();\"");
str = str.replace("<input type=submit","<input type=button onclick=\"javascript:window.parent.GoSearch() ;\"");
str = str.replace("<form name=f action=http://www.baidu.com/s", "<form1 name='f' actoin='#'");
return str
}
function GoPost()
{
if(window.frames[0].event.keyCode == 13)
{
GoSearch();
}
}
function GoSearch()
{
var value = window.frames[0].document.getElementsByName("wd")[0].value
alert(value);
var str = GetStringByUrl("http://www.baidu.com/s?cl=3&wd="+URLEncode(value),"get","");
str = GoReplace(str);
window.frames[0].document.body.innerHTML = str;
return false;
}
function GetStringByUrl(url,method,params)
{
var oxmlHttpForJs = null;
oxmlHttpForJs = new ActiveXObject("MSXML2.XmlHttp");
oxmlHttpForJs.open(method,url,false);
oxmlHttpForJs.setRequestHeader("cache-control","no-cache");
oxmlHttpForJs.setRequestHeader("charset","gb2312");
oxmlHttpForJs.send(params);
var res = "";
res = bytes2BSTR(oxmlHttpForJs.responseBody)
oxmlHttpForJs = null;
return res;
}//-->
</SCRIPT>