SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict greg76's Avatar
    Join Date
    Aug 2004
    Location
    Poland
    Posts
    262
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    innerHTML, pasteHTML - wysiwyg help

    Hi,

    I have been trying to modify slightly an old online wysiwyg that is based on an iframe.

    I am in need of surrounding a selection with my own bits of code (div, span). I have found here on SitePoint some code that is allegedly doing exactly what I need, but still I cannot make it work. What have I been doing wrong? Just to explain, I know very little JavaScript, and I spent couple of hours tonite trying to write a correct syntax for the variables (sigh)

    Code JavaScript:
    function catchSelection()
    {
    	var s_selected = window.getSelection();
    	var o_element = document.getElementById("idContent");
     
    	o_element.innerHTML = o_element.innerHTML.replace(s_selected, "<span style='background:#FF0000'>" + s_selected + "</span>");
    	o_element.focus();
    }

    Looking at the source codes of hundreds of wysiwygs today I noticed that there's something like pasteHTML, but I couldn't make that work, either. Also tried to use getIFrameDocument instead of getElementById but to no avail, error is printed idContent is not defined all the time.

    Can anybody help me here?
    Thanks in advance!

    Regards,
    Greg

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    pasteHTML is a "feature" of IE browsers that isn't supported by most other web browsers.

    This Introduction to Ranges provides good resources in regard to working with text selections.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •