I use jquery, php and html in my web application. I want to add a highlighting facility to allow users to highlight any text by selecting text then press a ‘highlight’ button .. how can I do it ?
<span id="text">
highlighted text
</span>
<button type="submit" name="highlight"></button>
When a user press this button, I wanna highlight any text that was selected, then save changing on text for any user. I’d also like the user to be able to select the highlight color.
This is a long text, maybe your answer, but this did not fit the comment zone;
First, some arguments, in order to help you decide what you should develop, what technologies to use;
jQuery or JavaScript ?
JavaScript, because if you use jQuery, the website from where you want to highlight, may not have jQuery;
Even if there is jQuery, it may be another version, and things will get messy, for you and on the website;
JavaScrpt is a common language, and you can use the Singleton concept;
Bookmarklet or Extension ?
Bookmarklet, because is very easy to inject data in a DOM.
If you develop a extension, thats a lot of work; you would have to develop the extension for Chrome, Mozilla, Internet Exploder as i call it (explorer), safari … and thats a lot of work;
Each browser has its own bugs, methods when extensions are involved, so use bookmarklet;
your app is simple, but there is a lot of code involved;
First, the Bookmarklet its a simple button, so it appears :))
This button, when clicked, it injects data into the DOM;
And this is where the app starts;
Your app will communicate with a server, thru javascript requests, within the webpage that you are viewing;
Also, you will have to attach/detach event listeners, for mouse down for example;
Also, all this highlighter process needs to be started; some parameters may be involved here, in order to know where to set the data in your form, by using unique id’s;
Is this hat you want ?
If yes, i will post code, soon;
And did i mentioned that you have a limitation of aproximatly 2096 characters when using the GEt method ?
And you also have to use JSON.stringify method when passing data from javascript to the server;
this is a tipycal bookmark button that uses javascript:
i used Yii MCV to generate this button, so ignore stuff with Yii…
my bookmarklet code is to big, but this is a short short version:
ps: this code does not work, because it is partial, its just for you to see what you want to do, and how its done; this is just the js part, the php part, where you catch and process the data, its up to you