> I'd like to know if it's possible to use js to step through and select a
header in an HTML document, select it's content and all content below it.
OK, only in the name of speach technologies! :-)
This is how it was done at NN4 times (with write() instead of innerHTML
of course).
Tested to work under Opera 8 / Windows.
Still they are looking very funny with all these text-to-speach
statements on the front page and the most essential methods missing in
their browser. Reminds me an investment seeker with X millions business
plan in his hand and a big blue under his left eye.
-------------------------------
<html>
<head>
<title>Pseudo-TextRange (Opera)</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<script type="text/javascript">
var myTextBlock = null;
var myLexems = [];
var myLexemsLength = 0;
var starter = null;
var timerID = null;
var myLexemReader = null;
var ptr = 0;
var re = /([\.\,\:\-\?\!])/;
function f1(thisStarter,myID) {
if (thisStarter.innerText.indexOf('start') != -1) {
thisStarter.innerText = 'Click here to stop';
myLexemReader = document.forms[0].elements[0];
myTextBlock = document.getElementById(myID);
myLexems = myTextBlock.innerText.split(' ');
myLexemsLength = myLexems.length;
timerID = window.setTimeout('f2()',1000);
}
else {
window.clearTimeout(timerID);
thisStarter.innerText = 'Click here to start';
timerID = null;
}
}
function f2() {
var startPoint = myLexems.slice(0,ptr).join(' ');
var endPoint = myLexems.slice(ptr+1).join(' ');
var selText = ' <span class="pseudoSelection">' + myLexems[ptr] +
'</span> ';
myTextBlock.innerHTML = startPoint + selText + endPoint;
myLexemReader.value = myLexems[ptr].replace(re," +[$1]");
ptr++;
if (ptr < myLexemsLength) {
timerID = window.setTimeout('f2()',1000);
}
else {
thisStarter.innerText = 'Click here to start';
ptr = 0;
}
}
</script>
<style type="text/css">
..pseudoSelection { color: #FFFFFF; background-color: #000000}
</style>
</head>
<body bgcolor="#FFFFFF">
<h2 onclick="f1(this,'p1')">Click here to start</h2>
<p id="p1">Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Phasellus in sem lacinia nunc rutrum tempor. Vivamus facilisis.
Vivamus lectus eros, aliquet id, tincidunt in, tempus quis, erat. Etiam
scelerisque sem et massa. Cum sociis natoque penatibus et magnis dis
parturient
montes, nascetur ridiculus mus. Ut at arcu. Praesent et turpis ac urna
ornare hendrerit.
Mauris vitae pede a libero scelerisque egestas. Nunc sollicitudin, orci
et
commodo ultrices, nisl libero vulputate urna, in posuere ligula arcu ut
libero. In
ullamcorper neque ut mi.</p>
<form>
<input type="text" name="output" size="32">
</form>
</body>
</html>