I want to use image files to represent a custom font, and it would copy the text value when selected and copied. is this possible with JavaScript?
-
Can you post an example? It is not very clear what you are trying to do.Oded– Oded2010-06-24 20:17:57 +00:00Commented Jun 24, 2010 at 20:17
-
I haven't written it yet. you can think of it as a rich text editor, when you copy and paste the image you just copied in a another editor (eg. notepad) you can text values.Yaso– Yaso2010-06-24 20:32:06 +00:00Commented Jun 24, 2010 at 20:32
-
Do you mean that you want to use images that represent text, but that can be selected and copied like normal text? In that case, perhaps I'd use @font-face; also see Bulletproof @font-face syntax.Marcel Korpel– Marcel Korpel2010-06-24 20:51:53 +00:00Commented Jun 24, 2010 at 20:51
1 Answer
I would look into alternatives. There is no need for images when it can be done completely cross-browser with something like Cufon or sIFR if Flash is an option.
Technically it would be possible with JavaScript, but it would be rather fragile. You would have to find a font that is "web-safe" (i.e. available on ~100% of computers) that scales more or less similarly to your custom font. Then you would have to overlay a SPAN element over the image (using absolute positioning) with this text in it, make it transparent and make sure it is at a font size similar to what is used in the image.
Messy to say the least.
Of course if you select an image and copy the selection, the alt text is copied, but I can't see this being very user-friendly. Besides, it can be pretty difficult to actually highlight just an image on a page.
1 Comment
span which size is determined by CSS. But it will be a mess, anyway.