Forum Moderators: open

Message Too Old, No Replies

Javascript Help Needed

To Rewrite Image URLs

         

inveni0

5:52 pm on Mar 8, 2008 (gmt 0)

10+ Year Member



Here's my problem:

I'm using FCKEditor as a web based html editor for my clients. The FCKEditor distribution is stored on my domain. PHP handles writing and retrieving files to/from their domain.

This all works fine; however, when the user is trying to use images within the FCKEditor GUI, the images naturally do not show because the URL written in the source is being searched for on MY domain, and not theirs.

I have two options, I think:

1) Require the user to save the file after adding an image, at which point PHP would replace "/media/file.jpg" with "http://www.example.com/media/file.jpg". This would work, but makes code so ugly, and the user would have to save their file before they're comfortable with the changes.

2) Write JavaScript that will rewrite the URLs browser side, then rewrite them again when PHP saves the file. This is a much better solution, I think. This would allow the user to arrange the images visually without having to dedicate the file to the server first.

My question is:

How do you change an IMG's SRC tag with JavaScript?

I appreciate any help, input or additional suggestions!

inveni0

5:55 pm on Mar 8, 2008 (gmt 0)

10+ Year Member



Was just thinking that a .htaccess redirect on the missing file/directory would be the easiest thing to do. Any ideas if this would be a better solution?

MarkFilipak

10:55 pm on Mar 8, 2008 (gmt 0)

10+ Year Member



Regarding changing the src attribute of an img-element:

myImgElement.setAttribute('src', '/path/to/new/file.jpg');