473,322 Members | 1,287 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Selecting a header and the content below it

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.

Context: I'm wondering if it's possible to use user javascript to extend
Opera 8's ability to be used as an aural browser. It has preliminary
support for aural CSS which can make a big difference in an author's
ability to tailor a better experience for aural access whilst retaining
the ability to include elements that are useful for visual access.

However Opera 8's capabilities seem geared towards creating voice
enabled applications. I presume Opera expects the feature to be used in
future as an alternative way to operate it's browser on mobile
platforms.

For Opera 8 to be used as an aural browser there are few options,
missing most notably is a non visual ability to select part of a
document to read out, such as navigating through a document's headers
and have a certain header and the content below it read out. Currently
the only option is to select all text and have that read out.

--
Spartanicus
Jul 23 '05 #1
6 2422
VK
> However Opera 8's capabilities seem geared
towards creating voice enabled applications.
I'm not sure where Opera 8 is geared to (did not have time yet to study
it). But text-to-speach and AI technologies are geared to SALT (Speech
Application Language Tags):

<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sasdk_salt/html/ST_Programmers_Reference.asp>

<http://www.w3.org/Voice/>

<http://www.saltforum.org/>

I admit that this is the main domain of my studies, and I invite you to
read these starting materials if you are serious about speach
technologies.
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.


As in the text range operations all wannabes are years behind of IE,
I'm using IE for this kind of scripting. *Of course* any of such
scripts (see a sample below) *may be emulated* on other browsers (the
algorithm is pretty clear). I just never did it myself as it would be a
boring and irrelevant to the matter task.

INTERNET EXPLORER ONLY:

<html>
<head>
<title>TextRange</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<script type="text/javascript">
var myTextRange = null;
var timerID = null;
var starter = null;
var out = null;

function f1(elm) {
starter = elm;
if (starter.innerText.indexOf('start') != -1) {
starter.innerText = 'Latina (Click to stop)';
out = document.forms[0].elements[0];
myTextRange = document.body.createTextRange();
if (myTextRange.findText('Lorem',null,2)) {
myTextRange.select();
out.value = myTextRange.text.toLowerCase();
timerID = window.setInterval('f2()',1000);
}
}
else {
f3();
}
}

function f2() {
myTextRange.moveStart('word');
myTextRange.expand('word');
myTextRange.select();
switch (myTextRange.text) {
case ', ' : out.value = '[period]';
break;
case '. ' : out.value = '[comma]';
break;
case '.' : f3();
default : out.value = myTextRange.text.toLowerCase();
}
}

function f3() {
window.clearInterval(timerID);
timerID = null;
myTextRange.collapse();
starter.innerText = 'Latina (Click to start)';
}
</script>
</head>

<body bgcolor="#FFFFFF">
<h3 onclick="f1(this)">Latina (Click to start).</h3>
<p>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 name="form1">
<input type="text" name="text1" size="32">
</form>
</body>
</html>

Jul 23 '05 #2


Spartanicus wrote:
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.


Opera 8 has made some efforts to implement a few parts of the IE/Win
text range selection and manipulation API but as far as I can tell it is
restricted to manipulating the selection in text controls.
IE's API is documented here:
<http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/objects/obj_textrange.asp>
so there you could do alike
var range = document.body.createTextRange();
var h1Elements = document.getElementsByTagName('h1');
for (var i = 0; i < h1Elements.length; i++) {
range.moveToElementText(h1Elements[i]);
range.select();
}
to select through the contents of <h1> elements.
Opera 8 however has no body.createTextRange method, the only way there
to get at a text range outside of a text control seems to be
var range = document.selection.createRange();
When I run some code to inspect such a range object it shows that many
methods IE implements are not implemented:

collapse: function collapse() { [native code] }
compareEndPoints: undefined
duplicate: function duplicate() { [native code] }
execCommand: undefined
expand: undefined
findText: undefined
getBookmark: undefined
inRange: undefined
isEqual: undefined
move: function move() { [native code] }
moveEnd: function moveEnd() { [native code] }
moveStart: function moveStart() { [native code] }
moveToElementText: undefined
moveToPoint: undefined
parentElement: undefined
pasteHTML: undefined
select: function select() { [native code] }
setEndPoint: undefined

As you can see moveToElementText for instance is not implemented and
IE's API does not have another method to relate a range to a DOM element
node so I see no way currently in Opera 8.01 to create a text range on
the contents of an element node and select that contents.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #3
Spartanicus <in*****@invalid.invalid> wrote:
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.


How do you define "content below it"?

Take a look at http://dean.edwards.name/my/cssQuery/ might do all you
need.

But AFAIK Opera doesn't have createTextRange(), so you cannot set a
selection.
Bye,
Martin
Jul 23 '05 #4
Martin Bialasinski <ag********@uni-koeln.de> wrote:
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.


How do you define "content below it"?


All content below a certain header (in the source).

--
Spartanicus
Jul 23 '05 #5
Spartanicus <in*****@invalid.invalid> wrote:
Martin Bialasinski <ag********@uni-koeln.de> wrote:
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.


How do you define "content below it"?


All content below a certain header (in the source).


If you have

H1 A
H2 B
H2 C
H2 D
H1 E

and the user selects "H2 B" wouldn't it be more useful to read from
"H2 B" to "H2 C" and not until the end of the document?

Bye,
Martin
Jul 23 '05 #6
VK
> 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>

Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Phil Powell | last post by:
I created a page that will be doing image resizing and manipulation, which seems to work (using GD library). However, upon returning to the page where the image has been changed, I still see the...
5
by: mr_burns | last post by:
hi, i am trying to create code that will prompt the user to download. below is the code i am using: .. .. ..
1
by: Ramesh | last post by:
hi, I am selecting fields from three table for manupulating data and i want to display total number of records selected. But i am always getting -1 value, eventhough 1000 of records are selected....
1
by: AndrewF | last post by:
Hi all, I am sure something like this has been covered somewhere so I am hoping a quick answer or pointer may suffice, however a couple of days trawling and I can't find anything on it. I'm...
16
by: Y.G. | last post by:
I am making a script which displays an RSS feed on my website. To do this I would like to take all the <div class="blabla"><img src="bla.jpg" alt="bla"> </div> tags and put them in front of my...
7
by: xkeops | last post by:
Thinking of creating a website, most of the pages will have a general toolbar menu, a content and a footer. The content will be the only one who's gonna change but the rest (header,footer) will...
2
by: ~john | last post by:
I'm trying to get my header to have 2 images, one for the top left and one for the top right. Here's a link to my page... http://levelwave.com/dev/div/index.html and will eventually be...
7
by: nonsensitor | last post by:
I'm having some trouble with horizontal navbars. In particular, I can't seem to get the width right for IE. I think I can resolve it if I can apply a separate style (via a class "lastnavitem") to...
1
by: Proogeren | last post by:
I have a problem with a httpwebrequest that I am creating. The request in itself looks correct but using fiddler I see that a www-authentication header is sent along as well. The code is pasted...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.