JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 3rd, 2003, 06:05 PM
pcarroll pcarroll is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 2 pcarroll User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
WYSIWYG Editor - innerHTML makes all links absolute?

I'm using a WYSIWYG Editor based on the article and it's working great... Except, any relative links added in WYSIWYG mode become absolute after calling doToggleView().

So the relative URL...

<a href="xxx.htm">

becomes absolute...

<a href="http://devserver.com/dir/xxx.htm">

It is happeneing at the call to...

iView.document.body.innerHTML = iText;

Obviously this is not great for portability. Has anybody found a solution?

iText has the correct form of the URL. Also, if you save the document without calling the doToggleView(), it is saved correctly.

Last edited by pcarroll : July 3rd, 2003 at 06:10 PM.

Reply With Quote
  #2  
Old July 3rd, 2003, 09:05 PM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 8 m 57 sec
Reputation Power: 9
Send a message via ICQ to stumpy Send a message via MSN to stumpy
What about performing a Regular Expression on your output (replacing the absolute data) just before saving the data to your DB (or whatever...i.e. when you're done editing)
__________________
DevArticles Moderator
BlueSix - Web Development and Consulting

Reply With Quote
  #3  
Old July 3rd, 2003, 09:46 PM
pcarroll pcarroll is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 2 pcarroll User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I tried that and it does sort of work.

document.editor.Body.value = oDiv.innerHTML.replace(/http:\/\/devserver.com/gi,'');

But it's hardly the right way to do it. It will eventually break, and when you're least expecting it...

I've noticed a couple of the commercial WYSIWYG editors do not have the problem, so I'm curious how the got around it. There must be a correct way. I'd also like to avoid the other tags it adds like <TBODY>.

I don't know enough about DOM-1 to know what the equivalent DOM-1 technique might be. I'd like a simple parsing of text>html without interpretation.

Reply With Quote
  #4  
Old December 27th, 2003, 09:16 AM
sonicus sonicus is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 1 sonicus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Any solution?

Hello PCarrol,

did you finally find any solution for relative links?

Reply With Quote
  #5  
Old March 25th, 2004, 10:35 AM
pelfed pelfed is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: Wiltshire- UK
Posts: 15 pelfed User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thumbs up innerHTML makes all links absolute - SOLUTION

Okay - this seems like an old thread, but there is a solution to the problem.

When toggling from source to html, the innerhtml function changes all path links to absolute. Having tried to find a solution I discovered that;

if you select all the text in source mode, cut it and then paste it, when you switch back to html mode the links are untouched. Not sure why this works but hey.

so in my code - all i do is add the following just before it switches back to html mode.

cmdExec('selectall'); cmdExec('copy'); cmdExec('paste'); sTmp=idContent.document.body.innerText;
idContent.document.body.innerHTML=sTmp;

hope this helps anyone

Reply With Quote
  #6  
Old March 25th, 2004, 09:56 PM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 8 m 57 sec
Reputation Power: 9
Send a message via ICQ to stumpy Send a message via MSN to stumpy
Haha - what a great little hack! - Nice work pelfed!

Reply With Quote
  #7  
Old April 18th, 2004, 05:23 PM
starrwriter starrwriter is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 5 starrwriter User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
absolute path hack doesn't work

Quote:
Originally Posted by pelfed

so in my code - all i do is add the following just before it switches back to html mode.

cmdExec('selectall');cmdExec('copy');cmdExec('past e')sTmp=idContent.document.body.innerText;
idContent.document.body.innerHTML=sTmp;

I'm fairly new to javascript and I can't get your hack to work in my WYSIWYG editor. I've tried plugging it into every place in the toggle function, but I get errors messages "object expected." As you can see from the script below, I already have one fix in the toggle function to keep the HTML mode background white so the source can be seen if the page background is dark. Exactly where do I plug in your script?

var prevbg = null;
function doToggleView() {
if(viewMode == 1)
{
prevbg = (iView.document.body.style.background)? iView.document.body.style.background : null;
iHTML = iView.document.body.innerHTML;
iView.document.body.innerText = iHTML;
if(prevbg) {
iView.document.body.style.background = "#FFFFFF"; }
viewMode = 2; // Code
}
else
{
iText = iView.document.body.innerText;
iView.document.body.innerHTML = iText;
if(prevbg) {
iView.document.body.style.background = prevbg; }
viewMode = 1; // WYSIWYG
}
}

Reply With Quote
  #8  
Old April 22nd, 2004, 03:55 PM
onesmoothdancer onesmoothdancer is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 1 onesmoothdancer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
copy & paste does the trick

Code:
//----- Convert WYSIWYG editor to HTML -----

if(viewMode == 1) {
	iHTML = editbox.document.body.innerHTML;
	alert( 'iHTML = ' + iHTML );
	editbox.document.body.innerText = iHTML;
	editbox.focus();
	viewMode = 2;
}

//----- Convert HTML editor to WYSIWYG -----
else{
	txtRange = editbox.document.body.createTextRange() ;
	txtRange.select();
	txtRange.execCommand("Copy");
	txtRange.execCommand("Paste");
	iText = editbox.document.body.innerText;
	alert( 'iText = ' + iText );
	editbox.document.body.innerHTML = iText;
	editbox.focus();
	viewMode = 1;
}

Reply With Quote
  #9  
Old April 22nd, 2004, 11:06 PM
starrwriter starrwriter is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 5 starrwriter User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
You're a genius! Works like a charm for relative links. I think I can even modify it to fix the problem of the editor using absolute paths for inserted images.

If you want a copy of the editor, let me know your email address and I will send it.

Thanks a lot,
Bill

Reply With Quote
  #10  
Old May 4th, 2004, 10:38 AM
marsha1979 marsha1979 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 1 marsha1979 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Smile

I would love to know how the relative path to the images can be done!

Reply With Quote
  #11  
Old May 4th, 2004, 07:14 PM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 8 m 57 sec
Reputation Power: 9
Send a message via ICQ to stumpy Send a message via MSN to stumpy
Did you try Pelfeds hack? (post #5)

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > WYSIWYG Editor - innerHTML makes all links absolute?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT