I have a template (blogContent.html) which loads the text on the page using helpers in (blogContent.js). Once the page has loaded, I'm trying to select some text on blogContent.html and highlight it.
To get the selected text, I'm trying to do something like this
Template.blogContent.onRendered(function(){
if (window.onSelection) {
var selectedText = window.onSelection().toString();
console.log(selectedText);
}
});
However, I'm encountering two issues with it. 1. The if block is always executed when the page is loaded and never afterwards i.e. not when I selected some text. 2. Because of (1), console.log outputs a null string on client console only once when the page loads and nothing heppens afterwards.
Any pointers are much appreciated. I'm new to webdev and meteor. Thanks a lot.