Textarea HTML Editor tool - URL path file://

Posted on 2009-12-24
Last Modified: 2013-11-19
The below code has something to do with it....the html editor that I am using, if you enter a http URL, no problem it works. But for some reason if I enter an internal URL like this: file://H:\folder name

I always get the result as: "file:///H:/folder name"  no matter what, it keeps adding an extra forward slash " / " in front of the file://. Is there anything wrong with the regular expression below? file:/// does not work, in outlook the file link works only with 2 slash file://H:/

try the demo here you'll see:
getDocumentPathOfUrl: function(url) {

		var path = null;


		// if local file system, convert local url into web url

		url = url.replace(/file:\/\//gi, "file://");

		url = url.replace(/\\/gi, "\/");

		var pos = url.lastIndexOf("/");

		if(pos != -1) {

			path = url.substring(0, pos + 1);


		return path;




	 * Get the documents url, convert local urls to web urls


	 * @param {DOMElement} doc Document which is used to get the url


	getDocumentUrl: function(doc) {

		// if local file system, convert local url into web url

		var url = doc.URL;

		url = url.replace(/file:\/\//gi, "file://");

		url = url.replace(/\//gi, "/");

		return url;


Open in new window

Question by:clubzone
    LVL 58

    Accepted Solution

    It is doing it correctly. In the local file URLs three slashes are needed. See the explanation.

    Author Comment

    The thing is I use this with my work Intranet server and 3 slashes does not work, people needs to link to Internal file server, therefore it has to be set to file://D:\folname\thisfile.xls

    even if I enter 2 // instead of 3 manually, it automatically puts it back to 3 slashes, why is it doing this, and how to fix it for my behalf.
    LVL 58

    Expert Comment

    What o/s and browser are you targeting (for the client not the web server)?

    Author Comment

    windows XP Pro and IE6.0

    Author Comment

    well it seems to work now! the server has to match exactly. the lower and upper case made the difference. if I were to type in file:///h:/intranet instead of file:///H:/INTRANET it would not work, if you match it exactly it works, I did not know lower uppercase made the difference? strange.

    Author Closing Comment

    Thanks for the link.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Suggested Solutions

    Article by: Matthew
    I am a very big proponent of technology compliance standards and strive to meet such criteria in all of my work. That includes my site, which is 100% XHTML 1.0 compliant as determined by the World Wide Web Consortium. https://www.matthewstevenkel…
    Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to dynamically set the form action using jQuery.

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now