SitePoint Sponsor

User Tag List

Results 1 to 17 of 17
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2005
    Location
    Place d'Italie
    Posts
    128
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can I do this without any server side language???

    Hey, guys.
    I want that my site's clients can write a message to their friends to promote my site. I'd like ask if I can realise it without any server side language such as PHP or ASP, but just javascript?
    Here is my code:
    HTML Code:
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Untitled Document</title>
    </head>
    
    <body>
    <SCRIPT language=javascript>
     function sendmail()
     {var dest=form.r_email.value;
      return dest;
      } 
    </SCRIPT>
    <FORM action="mailto: javascript sendmail()" method="post" name="sendsong" target="_self">
        The name of your friend: 
        <input name="recipients" type="text" id="recipients" size="30" maxlength="45">
        <br>
        The Email of your friend: 
        <input name="r_email" type="text" id="r_email" size="39" maxlength="45">
        <br>
        Your message: 
        <textarea name="zhufu" cols="50" rows="8" id="zhufu"></textarea>
        <br>
        <input class=normal name=SendSong type="submit"  value="Envoyer" style="margin:0 0 0 150px;">
    	<input type="reset" value="Remettre">
        </form>
    </body>
    Well, I'm a javascript novice, I donn't know if the action="mailto: javascript sendmail()" is grammatically correct. Please help me solve this.
    Thanks very much for anybody giving advice.
    Best regards,

  2. #2
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can't do that. And relying on visitors having mailto: setup is a bad idea.
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  3. #3
    &#083;itePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The mailto: protocol specifier isn't very reliable. Here's an example that uses JavaScript to create an email, but it has a mailto: specified as a backup if JS is turned off:

    Code:
     <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
     <html>
     <head>
     <title>Untitled</title>
     <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
     <script type="text/javascript">
     function sendMail(_frm){
       var eml="you@youraddress.com";
       var bod="&body="+_frm.selOne.value+" || "+_frm.txtOne.value;
       var subj="?subject=Whatever you want";
       document.location="mailto:"+eml+subj+bod;
     }
     </script>
     </head>
     <body>
     <form action="mailto:you@youraddress.com" enctype="text/plain" 
       method="POST" onsubmit="sendMail(this);return false;">
       <select name="selOne">
     	<option value="Dog">Dog</option>
     	<option value="Cat">Cat</option>
       </select>
       <textarea name="txtOne"></textarea>
       <input type="submit" value="Submit" />
     </form>
     </body>
     </html>

  4. #4
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The JavaScript script is still using mailto. It's just formatting the query string.
    Code:
       document.location="mailto:"+eml+subj+bod;
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  5. #5
    &#083;itePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You will find, however, when it is called through JavaScript, it functions more consistently between browsers than when called through the action attribute of the form. Particularly, with IE many users find that the body of the email is blank when using the action attribute.

  6. #6
    SitePoint Zealot
    Join Date
    Mar 2005
    Location
    Place d'Italie
    Posts
    128
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by JVLB
    You will find, however, when it is called through JavaScript, it functions more consistently between browsers than when called through the action attribute of the form. Particularly, with IE many users find that the body of the email is blank when using the action attribute.
    JVLB, sorry to bother you again, but I really donn't understand the syntax of your writing.
    As I find out from the Netscape's js guide, the
    document.location permit to specigy the URL and the Mailto is included. The ? is the search string mark, isn't it? and the & is to seperate two pairs of search strings. But why you write it as document.location="mailto:" +eml+subj+bod, not as document.location="mailto:+eml+subj+bod" which seems similar to the syntax presented by Netscape?
    Anyway, I tried it in both way, but till this moment I haven't yet received anything in my mailbox.
    Moreover, I have added an alert(document.location) in my code. The value returned is the address of the current file on the local disc, not the mailto one, strange.

  7. #7
    &#083;itePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When you fire the alert, you are polling the current document.location. When you do "document.location=~" you are assigning a new value to the document.location property. In the case of the mailto specifier, this calls the default email client.

    In the string that assigns the value to the location property, "mailto:" is quoted because it is a string literal; eml, subj and bod are variables that already contain strings. If you put quotes around them they become literal strings with the value "eml", for instance, not "you@youraddress.com". Do not confuse the use of the & and ? in email composition with their use in GET strings in the URL of a page. The two applications are completely separate and unrelated.

  8. #8
    SitePoint Zealot
    Join Date
    Mar 2005
    Location
    Place d'Italie
    Posts
    128
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by JVLB
    When you fire the alert, you are polling the current document.location. When you do "document.location=~" you are assigning a new value to the document.location property. In the case of the mailto specifier, this calls the default email client.

    In the string that assigns the value to the location property, "mailto:" is quoted because it is a string literal; eml, subj and bod are variables that already contain strings. If you put quotes around them they become literal strings with the value "eml", for instance, not "you@youraddress.com". Do not confuse the use of the & and ? in email composition with their use in GET strings in the URL of a page. The two applications are completely separate and unrelated.
    Well, one more question.
    you mentionned the default email client, what is that? you@youraddress.com that you assigned to eml?
    Actually, I want my site client designate their own desired recipient. So can I write like this:
    HTML Code:
    var eml=form.recipientemail.value
    Is that correct?

  9. #9
    &#083;itePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your syntax for the assignment to eml looks correct. Mine is just a stock example, not intended to solve a specific problem, but to illustrate the technique. The default email client is the one the user has specified, such as Outlook or Thunderbird.

  10. #10
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Meaning that the user has to have an email client configured for this to work.

    document.location is deprecated; use location.href instead.

    Quote Originally Posted by JVLB
    Do not confuse the use of the & and ? in email composition with their use in GET strings in the URL of a page. The two applications are completely separate and unrelated.
    I don't see how they are unrelated. The question mark (?) still specifies the beggining of the query string and the ampersand (&) still separates the name/value pairs.
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  11. #11
    &#083;itePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The question mark specifies the subject in an email and the ampersand the body. It is not GET data, it does not get put in a URL that is passed to the server and it is not processed by the server.

    Technically, of course, the full syntax is window.location.href, document.location having been most directly supplanted by document.URL, with the window.location property generally being preferred.

  12. #12
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by JVLB
    The question mark specifies the subject in an email and the ampersand the body. It is not GET data, it does not get put in a URL that is passed to the server and it is not processed by the server.
    I never said it was processed by a server.
    I just tested it in Mozilla Thunderbird and Outlook Express 6. Both of the following lines of code work.
    Code:
    mailto:email@example.com?subject=my+subject&body=some+text
    mailto:email@example.com?body=some+text&subject=my+subject
    Quote Originally Posted by JVLB
    Technically, of course, the full syntax is window.location.href, document.location having been most directly supplanted by document.URL, with the window.location property generally being preferred.
    True. However since window is the global element it is assumed and thus unnecessary.
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  13. #13
    &#083;itePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not clear on the point you wish to express with your mailto: examples. Could you elaborate?

    My reference to the window's ownership of the location property was purely intended as a didactic enhancement to the discussion.

    Perhaps the incongruity here is the interpretation of 'separate'. Syntactically the two usages of name/value pairs share common characteristics, but from a process standpoint they are significantly decoupled.
    Last edited by JVLB; Apr 7, 2005 at 20:08. Reason: Potential insight

  14. #14
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There are similarities and differences. It seems to me that there are more simularities than there are differences. One is sent to a web server, the other is sent to an email client. They are both programs that process the information.

    My point was that the order of subject and body do not matter and that the question mark and ampersand are only separators and do not indicate which name/value pair is for the body and which is for the subject. Basically I was saying that your point was incorrect.

    http://www.ianr.unl.edu/internet/mailto.html
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  15. #15
    &#083;itePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Upon review, I see my rushed comments about the question mark and ampersand were decidedly unclear and for that I apologize. What I was trying to express was that those values caused the creation of properties attached to a local object.

    mailto:, http:, and ftp: are all web protocols, in that they are related, but there the relationship largely ends. Most people would find it a stretch to say a conversation in Madrid in Spanish about tulips is related to one in San Francisco, in English, about aromatic hydrocarbons. But, since both are Indo-European languages and those who are are conversing are human, they must be related, eh?

    Neither the data nor the processes of the two protocols interact; I find it hard to assert a functional relationship there. Then again, I hear that in relationships dysfunction is all the rage, these days.
    Last edited by JVLB; Apr 8, 2005 at 06:20.

  16. #16
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I agree with most of your last reply.

    However, I will say that from the user's perspective http:// and mailto: both can have query strings and thus behave similarly. I know that behind the scenes they are handled very differently, but that is hidden from users.
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  17. #17
    &#083;itePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I see your point, but I think it is important to be clear that the similarity is more syntactic than functional.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •