How to highlight some text in an iframe by script?

mylittlejava 2004-11-23 12:46:59
hi, all
I have an iframe in my page. Actually what I want is just like the google search.
When user clicks search, I will load the a page from another URL into iframe and then highlight the key words in the iframe.
Does anyone know how to do this? By JS or VBScript?

Thanks
...全文
84 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
ice_berg16 2004-11-23
  • 打赏
  • 举报
回复
first one
if the page you load is not in your own domain, you cant change its content and you
can use xmlhttp parse the source code, then do what you want.

second
the page you load in your own domain, the you can do it by the follow way

var str = window.frames['iframeName'].document.body.innerHTML;
str = str.replace("keyword", "<span style='color:red'>keyword</span>");
window.frames['iframeName'].document.body.innerHTML = str;
ttyp 2004-11-23
  • 打赏
  • 举报
回复
<HEAD>
<SCRIPT>
function fnNAF(){
window.external.NavigateAndFind(
"http://www.domain.ext/path/file.htm",
oSearchText.options[oSearchText.selectedIndex].text,"");
}
</SCRIPT>
</HEAD>
<BODY>
<SELECT id=oSearchText onchange="fnNAF()">
<OPTION>Persnickety
<OPTION>Seattle rain
<OPTION;> ...
</SELECT>
</BODY>
DARKNESSFALL 2004-11-23
  • 打赏
  • 举报
回复
xmlhttp
only

87,993

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧