DavidB12345
Technical User
On page with a lot of text, highlighting the specific text focuses the user's attention on the information you want to be seen.
To highlight specific text on a page use the following code:
Page.htm
<HTML>
<HEAD>
<TITLE></TITLE>
<script language="JavaScript"><!--
function bgon(lnk) {
document.anchors(lnk).style.background= 'lime';
}
<!-- Turn off background color of link for current page -->
function Bg_off(colr2) {
for (var i = 0; i < document.anchors.length; i++)
document.anchors.style.background='';
document.anchors.style.color = colr2;
}
//--></script>
</HEAD>
<BODY>
<A HREF="#link2" OnClick="bgon('link2');">Highlight text on this page</A></A>
<p>
<p>
<A NAME="link2">Highlighted from link on this page</A>
</BODY>
</HTML>
I am trying to go from link on 1 page to a second page and highlight text at specific location (anchor). I can pass a variable to page 2 but it is not seen by the code I am using to set the background color:
window.document.anchors(tst).style.background= 'lime';
Any suggestions on how to set the background color on page 2.htm from page 1.htm ??
Thanks.
Page 1.htm
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<script language="JavaScript"><!--
var variableName = 'hilink'; <!-- name of link to be passed to second page-->
//--></script>
<a href="highlighted page.htm" onClick="this.href='highlighted page.htm?' + variableName">Text on Linked Page</a>
</BODY>
</HTML>
Highlighted Page.htm
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE></TITLE>
<script language="JavaScript"><!--
var variableName = null;
if (location.search.length > 0)
variableName = location.search.substring(1);
function functionName(text) {
var tst =text <!-- used to pass variable from another page to this page-->
alert(tst); <!--display the variable for testing purposes-->
<!-- set the background color of the linked text - NOT WORKING -->
window.document.anchors(tst).style.background= 'lime';
}
functionName(variableName);
<!-- Set background color of link for current page -->
function bgon(lnk) {
document.anchors(lnk).style.background= 'lime';
}
<!-- Turn off background color of link for current page -->
function Bg_off(colr2) {
for (var i = 0; i < document.anchors.length; i++)
document.anchors.style.background='';
document.anchors.style.color = colr2;
}
//--></script>
</HEAD>
<BODY onLoad="bgon(tst)"> <!-- load the background color passed from page 1.htm-->
<A HREF="#link2" OnClick="bgon('link2');">Highlight text on this page</A></A>
<p>
<p>
<A NAME="link2">Highlighted from link on this page</A>
<p>
<p>
<A NAME="hilink" OnMouseOver="Bg_off('black');">Text highlighted from another page</A>
<p>
<p>
</BODY>
</HTML>
To highlight specific text on a page use the following code:
Page.htm
<HTML>
<HEAD>
<TITLE></TITLE>
<script language="JavaScript"><!--
function bgon(lnk) {
document.anchors(lnk).style.background= 'lime';
}
<!-- Turn off background color of link for current page -->
function Bg_off(colr2) {
for (var i = 0; i < document.anchors.length; i++)
document.anchors.style.background='';
document.anchors.style.color = colr2;
}
//--></script>
</HEAD>
<BODY>
<A HREF="#link2" OnClick="bgon('link2');">Highlight text on this page</A></A>
<p>
<p>
<A NAME="link2">Highlighted from link on this page</A>
</BODY>
</HTML>
I am trying to go from link on 1 page to a second page and highlight text at specific location (anchor). I can pass a variable to page 2 but it is not seen by the code I am using to set the background color:
window.document.anchors(tst).style.background= 'lime';
Any suggestions on how to set the background color on page 2.htm from page 1.htm ??
Thanks.
Page 1.htm
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<script language="JavaScript"><!--
var variableName = 'hilink'; <!-- name of link to be passed to second page-->
//--></script>
<a href="highlighted page.htm" onClick="this.href='highlighted page.htm?' + variableName">Text on Linked Page</a>
</BODY>
</HTML>
Highlighted Page.htm
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE></TITLE>
<script language="JavaScript"><!--
var variableName = null;
if (location.search.length > 0)
variableName = location.search.substring(1);
function functionName(text) {
var tst =text <!-- used to pass variable from another page to this page-->
alert(tst); <!--display the variable for testing purposes-->
<!-- set the background color of the linked text - NOT WORKING -->
window.document.anchors(tst).style.background= 'lime';
}
functionName(variableName);
<!-- Set background color of link for current page -->
function bgon(lnk) {
document.anchors(lnk).style.background= 'lime';
}
<!-- Turn off background color of link for current page -->
function Bg_off(colr2) {
for (var i = 0; i < document.anchors.length; i++)
document.anchors.style.background='';
document.anchors.style.color = colr2;
}
//--></script>
</HEAD>
<BODY onLoad="bgon(tst)"> <!-- load the background color passed from page 1.htm-->
<A HREF="#link2" OnClick="bgon('link2');">Highlight text on this page</A></A>
<p>
<p>
<A NAME="link2">Highlighted from link on this page</A>
<p>
<p>
<A NAME="hilink" OnMouseOver="Bg_off('black');">Text highlighted from another page</A>
<p>
<p>
</BODY>
</HTML>