By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,594 Members | 3,680 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,594 IT Pros & Developers. It's quick & easy.

Link defined in 'var' breaking at space chars

P: 57
Ok, the title might not make it clear.

I have a javascript code which generates an email. The page is on our corporate intranet so I know it will fire up the email ok.

the code looks something like this:

Expand|Select|Wrap|Line Numbers
  1. var ct9000 = document.getElementById("ct9000").value;
  2. var enddate = document.getElementById("105end").value;
  3. var fileloc = "file:///S:\folder1\folder2\folder - 3 \document.doc'";
  4. var body_message = "Please run "+job+", details as below:%0D%0DCT9000 ID: "+ct9000+"%0DEnd Date: "+enddate+"%0DATTN IT Ops Officer:%0DJob Notes at%0D"+fileloc;
  5. var mailto_link = 'mailto:'+email+'?subject='+subject+'&body='+body_message; 
  7. win =,'emailWindow'); 
  8. if (win && &&!win.closed) win.close();
So you can see the link is predenfined in the "var fileloc" line, and it contains spaces. When the email is generated the link breaks at the space character, causing the link to fail.

I have tried replacing the space characters with %20 - but the same thin happens.

You could argue that I could change the path so it doesn't contain spaces, but there are so many different paths/files that it would make it a mamoth task.

Thanks in advance...
Jan 10 '08 #1
Share this Question
Share on Google+
5 Replies

Expert Mod 15k+
P: 16,027
Change the backslashes into forward slashes.
Jan 10 '08 #2

P: 57
Change the backslashes into forward slashes.

Thakns for the suggestion but it still ends the link when it reaches the first space (or is %20 equivelant).....
Jan 11 '08 #3

Expert Mod 15k+
P: 16,027
Why do you need to use for the mailto link? A mailto link should open the default mail application.
Jan 11 '08 #4

P: 57
You're right, it does.

But i still have the problem of it not putting in the whole link......
Jan 11 '08 #5

Expert Mod 15k+
P: 16,027
Use encodeURIComponent, e.g.
Expand|Select|Wrap|Line Numbers
  1. var mailto_link = 'mailto:' + encodeURIComponent(email) + '?subject=' + encodeURIComponent(subject) + '&body=' + encodeURIComponent(body_message);
Jan 11 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.