473,394 Members | 1,787 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

absolute path problem

Another problem with absolute paths in the WYSIWYG editor I'm putting
together.

The function to toggle between WYSIWYG and HTML modes works except for
one glitch. If you use a relative path for a link, like <a
href="download.htm">Click Here</a>, the editor returns an absolute
path the second time you toggle HTML mode: <a
href="C:\Windows\Desktop\Editor\download.htm" and even adds file:///
on the third try. This path must be manually deleted before uploading
the page to your web host, which partially defeats the purpose of a
WYSIWYG editor.

I thought I had the problem fixed when I found a hack on a javascript
forum. The poster noticed the relative path was retained if he
manually selected the source code in HTML mode, copied it and then
pasted it. So he came up with a hack to make these operations
automatic.

He said he placed this hack in the toggle script "just before it
switches back to WYSIWYG mode." I have tried inserting it between
every single line of the toggle script with no luck. First I got error
message "object expected" until I embedded it as a second function
called relpath(). Then, as I moved the hack from line to line in the
toggle script, either the editor refused to return to WYSIWYG mode or
it copied the source code into the WYSIWYG mode. I know this works if
you manually select all-copy-paste because I've tried it.

Can anyone tell me where in blazes the hack fits into the toggle
script? The hack creator has apparently abandoned the forum where he
made the original posting.

THE HACK:
function relpath() {
cmdExec('selectall');cmdExec('copy');cmdExec('past
e');
sTmp=iView.document.body.innerText;
iView.document.body.innerHTML=sTmp;}

THE TOGGLE FUNCTION:
function doToggleView()
{
if(viewMode == 1)
{
iHTML = iView.document.body.innerHTML;
iView.document.body.innerText = iHTML;
viewMode = 2; // Source Code
}
else
{
iText = iView.document.body.innerText;
iView.document.body.innerHTML = iText;
viewMode = 1; // WYSIWYG
}
}
Jul 23 '05 #1
1 3081
William Starr Moake wrote:
The function to toggle between WYSIWYG and HTML modes works except for
one glitch. If you use a relative path for a link, like <a
href="download.htm">Click Here</a>, the editor returns an absolute
path the second time you toggle HTML mode: <a
href="C:\Windows\Desktop\Editor\download.htm" and even adds file:///
on the third try. This path must be manually deleted before uploading
the page to your web host, which partially defeats the purpose of a
WYSIWYG editor.


Such WinDOS paths are invalid as value of the "href" attribute, even for
local HTML documents. That attribute is of type URI (see HTML 4.01
sections 12.2, 12.3, 12.4 and 13.6.1, and RFC 2396), so if the UA returns
a WinDOS path, you must convert it:

function winDOS2URI(sPath)
{
if (/^[a-z]:/i.test(sPath))
{
sPath = "file:///" + escape(sPath.replace(/\\/g, "/"));
}

return sPath;
}

If you want to allow absolute local paths in documents to be published
online, your editor needs a pref for the local web root. If the user
wants to publish the document, you need to convert the paths:

function getRelativeFromAbsolute(sPath, sRoot)
{
return winDOS2URI(sPath).replace(
new RegExp("^" + winDOS2URI(sRoot) + "/?"),
"");
}

var sRemoteURI = getRelativeFromAbsolute(
theFile.absolutePath, sLocalWebRoot);

You may have to deal with the remote web root as well.
HTH

PointedEars
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: dchaffin | last post by:
I'm having a problem using file_exists with an absolute path and I can not figure out why. I tried the exact example that is on www.php.net ... <?php $filename = '/path/to/foo.txt'; if...
3
by: rajuvk | last post by:
I am setting up a website with a number of folders like: / (the document root) /user /admin/ /content in the /user folder there is a flie "userlogged.php", which I want to include in every...
9
by: Stuart | last post by:
Hi All, I got a challenge to make the same APS/Script/Html run on different web roots. I can not use relative pathing in a lot of cases. We use lots of included files so depending on where that...
15
by: Nick K. | last post by:
I recently began maintenance work on a production web server that is located in the root directory of a web server. I moved this into a sub web on my local web server in order to do work on it. I...
7
by: Rizaan Jappie | last post by:
is it possible to get the relative path based on a absolute path in c#? *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
2
by: mhadi | last post by:
Hi All, I am developing a solutions for clients to run some webpages. Since there is no webserver the ASP route is a No Go. So I am using Javascript to connect to my database. The Problem is that...
3
by: JeffDotNet | last post by:
I wrote a small data processing application that writes a summary of several hundred files. I use drag and drop on a panel (Panel1) to grab the absolute path to each of these files. Then I begin...
19
by: Jerry M. Gartner | last post by:
Greetings: What is the best way to resolve paths within a document regardless of what path it is opened under? For example: I have x.php and it contains <img src="images...">, (amongst other...
6
by: Jon Slaughter | last post by:
do I have to prefix every absolute path with document root to get it to work? For some reason I thought that prefixing a path with '/' or './' with make it absolute w.r.t to document root but I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.