Highlight/mark text in browser

Just starting out? Need help? Post your questions and find answers here.
DevilDog
Enthusiast
Enthusiast
Posts: 210
Joined: Thu Aug 04, 2005 9:32 pm
Location: Houston, Tx.

Highlight/mark text in browser

Post by DevilDog »

Hey all,
I'm not sure if this is doable or not but here goes. I need a way to highlight a specific word(s) in Internet Explorer.

I know from looking at the IE Tool source that it's possible to access the text of the browser window, but here's the next step: I want to be able to either change the text color of a word(s) or maybe draw a semi-transparent window over it. In order to draw a window over it I would need to be able to determine the x,y location of the text wouldn't I?

Anyone have any idea some api commands I should look at or any other advice?

TIA
When all is said and done, more is said than done.
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

Search for a java script that you can call !
Beach
Enthusiast
Enthusiast
Posts: 677
Joined: Mon Feb 02, 2004 3:16 am
Location: Beyond the sun...

Post by Beach »

Here is an example of how to highlight text for IE (does not work with Mozilla/Firefox)

Online example:
http://www.penguinbyte.com/apps/pbwebst ... light.html

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Highlight test</title>
<script language="JavaScript" type="text/javascript">
function HighlightText() {
  var formInput = document.getElementById("highlight").value ;
	var BodyHtml = document.getElementById("bodytext").innerText;
	document.getElementById("bodytext").innerHTML = BodyHtml;
	var RegText = new RegExp(formInput,"g")
	var StyledText = "<span class='highlighter'>" + formInput + "</span>";
	BodyHtml = BodyHtml.replace(RegText,StyledText);
	document.getElementById("bodytext").innerHTML = BodyHtml
}
</script>
<style>
.highlighter {
  color: #000000;
  background-color: #ffff00
}
</style>
</head>
<body>
Enter text to highlight: <input name="highlight" type="text">
<input type="button" name="go" value="Go" onClick="HighlightText();">
<p>&nbsp;</p>
<div id="bodytext">PureBasic is a programming language based on 
  established BASIC rules. The key features of PureBasic are 
  portability (Windows, AmigaOS and Linux are currently fully supported), 
  the production of very fast and highly optimized executables and, of 
  course, the very simple BASIC syntax. PureBasic has been created for 
  the beginner and expert alike. We have put a lot of effort into its 
  realization to produce a fast, reliable and system friendly language.
</div>
</body>
</html>
-Beach
DevilDog
Enthusiast
Enthusiast
Posts: 210
Joined: Thu Aug 04, 2005 9:32 pm
Location: Houston, Tx.

thank!

Post by DevilDog »

Hey guys thanks for the replies and info.

The highlighter code looks very interesting, I'll have to delve deeper into what it's doing.

So is it impossible to find the coordinates of a word in the browswer (x,y)?

Anyone?
When all is said and done, more is said than done.
Post Reply