Solved

Toggling mode in tich text editor changes relative links to absolute

Posted on 2004-09-08
2
328 Views
Last Modified: 2008-01-09
Hello.

I am using a simple rich text editor that I like very much.  But it is doing something wierd with the links!  When I add a link, relative link, everything works fine.  When I views the source using toggleHTMLSrc(rte) the link shows up as relative.  But when I click to go back into editing mode, again calling toggleHTMLSrc(rte), the link is turned into an absolute link!  This is messing things up because the editor is in the admin directory.

Any idea what is going on here?

Thanks!


-----------------------------
function toggleHTMLSrc(rte) {
      var oRTE;
      if (document.all) {
            oRTE = frames[rte].document;
      } else {
            oRTE = document.getElementById(rte).contentWindow.document;
      }
      
      if (document.getElementById("chkSrc" + rte).checked) {
            document.getElementById("Buttons1_" + rte).style.visibility = "hidden";
            document.getElementById("Buttons2_" + rte).style.visibility = "hidden";
            document.getElementById("Buttons3_" + rte).style.visibility = "hidden";
            if (document.all) {
                  oRTE.body.innerText = oRTE.body.innerHTML;
            } else {
                  var htmlSrc = oRTE.createTextNode(oRTE.body.innerHTML);
                  oRTE.body.innerHTML = "";
                  oRTE.body.appendChild(htmlSrc);
            }
      } else {
            document.getElementById("Buttons1_" + rte).style.visibility = "visible";
            document.getElementById("Buttons2_" + rte).style.visibility = "visible";
            document.getElementById("Buttons3_" + rte).style.visibility = "visible";
            if (document.all) {
                  //fix for IE
                  var output = escape(oRTE.body.innerText);
                  output = output.replace("%3CP%3E%0D%0A%3CHR%3E", "%3CHR%3E");
                  output = output.replace("%3CHR%3E%0D%0A%3C/P%3E", "%3CHR%3E");
                  
                  oRTE.body.innerHTML = unescape(output);
            } else {
                  var htmlSrc = oRTE.body.ownerDocument.createRange();
                  htmlSrc.selectNodeContents(oRTE.body);
                  oRTE.body.innerHTML = htmlSrc.toString();
            }
      }
}
-------------------
0
Comment
Question by:hankknight
2 Comments
 
LVL 1

Accepted Solution

by:
Webby_ earned 500 total points
ID: 12009997
I don't have a javascript solution for this one, but in my time as webdeveloper i've encountered the same problem.
We always used a simple workaround. You say admin, so i guess the data gets posted and parsed in a serverside language. Simply replace the "/admin" for "" before you put the data into the database..
0
 
LVL 16

Author Comment

by:hankknight
ID: 12010156
I thought I was going crazy (and the only person to ever run into this)

Glad to hear I'm not loosing my mind . . .
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question