If a user select some text from the article of a webpage then show share and copy button for the following selected text.
I want to do something like this..
the guardian
There is no inbuilt event for text selection but you can use
onmouseup this would be invoked whenever user releases his left mouse button. After every such event we can check if the user has selected any text or not
window.getSelection() to test for any text selection. If the selected text is not an empty string, you can invoke your function which would show up required buttons
Here is an example with code (note - uses jQuery)
SOURCE
Related
Problem - Watch for active input boxes in a page and trigger events if specific words are entered into the input box
Steps
Click 'reply or reply all'
Input box becomes active
Enter |intro
|intro text gets replaced with long form version. The |intro is like a snippet or short code
Heres what I'm thinking
Query all input boxes on a page
Check for input with focus
Add event listener on input to check for keyup events
Conditional statement to check if string contains specific snippet/short code
If condition is met then replace snippet with long form text
What do you think of my approach to this functonality
I have a text box that lets the user select the zip code. If the user types on the zip code in the text box like 226016 and move away from the text box, then onblur event fires and my JavaScript code is called.
I have a pick link button right next to the text box that opens up the popup menu that has the list of zip codes and it lets the user pick the zip code in case the user does not know the zip code. When the user selects the zip code from the pick menu and the zip appears in the text box, then none of the events fire if I click on another text box.
I want a JavaScript event to be fired when the user types in the zip code and moves away from the text box and when the user selects something from the popup menu and the zip code appears in the text box.
When the zip code appears from the popup menu to the text box, then even if I click on another text box, my JavaScript event does not get fired. I have an onblur event on my text box right now.
This is my code
<asp:TextBox ID="TXTCode" runat="server" CssClass="txtReview" Width="30" MaxLength="2" onkeyup="javascript:HidePick(this);" onblur="javascript:TestThis(this);">
function TestThis(selectObj) {
if (selectObj.value.toUpperCase() == "j1") {
// do something
}
}
Any help will be appreciated.
It isn't firing because you are comparing a .toUpperCase() string to "j1" and inherently non uppercase string.
I have some text content displayed on a UIWebView which is plain html. The current paragraph is highlighted in yellow and the user has selected the word 'If the'. (link to image: http://i.stack.imgur.com/GKp9h.png)
1) When the user selects some text on the uiwebiew, how do I perform dynamic highlighting? i.e. as the user is selecting text, what ever text is selected gets highlighted in purple?
For instance, I like the words 'If the' to be highlighted in purple (maybe using window.getSelection() ? ) and that this behaviour is dynamic such that as the user selects subsequent words, these words under selection gets highlighted in purple.
What I am struggling with at the moment is:
1) What event handler (JavaScript or iOS) should I listen to, when the user is selecting some text on the uiwebview? This is before the uimenucontroller opens up.
2) Once, I get the selected text (using window.getSelection(), how do I modify the DOM in a clean efficient way such that the selected text gets highlighted?
I suppose for 2) I cannot directly use style.backgroundColor=<hex code of purple>
There's a very similar question here: How to get selection text from UIWebView?
From the accepted answer there, looks like this might answer your question: http://zaldzbugz.posterous.com/how-to-mark-or-get-the-highlighted-string-ins/ There's a discussion about getting and styling the text selection in a web view.
I have a two items(rows) in the list box
I love to work with jquery
i love to work with javascript
I have textbox and button when I enter love in the text box when I click button i need to loopthrow this list box to find the text love and change that love text color? to yellow.
thanks
first of all, jQuery is javascript, it's a library written in javascript.
So, If I understand your problem, you have 3 interactive elements on your page:
a list box containing a list of words
a text field for the user to enter a word
a button for the user to click when he has written the text.
And you want the option to change color when the user clicks the button.
the code for thsi would be something like this:
$("#mybutton").click(function(){
var text = document.getElementById("mytextinput").value
$("#lstCodelist option").each(function (){
if(this.text()===text)
this.css('color':'yellow');
});
});
this is what happens:
line 1: I define a click handler when the button gets clicked.
line 2: I get the text from inside the textbox, I use getElementById to avoid the overhead of using jQuery for something that simple
line 3: I loop over each of the items in the list.
line 4: if the string in the textbox equals the text inside the option:
line 5, change the css property of the list option.
So no, this is not affecting the text, it only edits the css.
for changing text box color, you can add class to the element
addClass("myClass yourClass");
http://api.jquery.com/addClass/
I have one text box immediately after that one button. If i click on that button dynamically i get one more text box, but the focus is not coming to new text box. Can any one suggest something.
Thanks in advance
Venkat
You need to execute element.focus() on the new texbox after its insertion to give it focus.
E.g.
var element = document.getElementById('newElementId');
element.focus();
Also available in jQuery
$('#newElementId').focus();