Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    New to the CF scene
    Join Date
    Apr 2008
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    External jscript Using "Mailto"

    I searched high and low for help with this - I am doing a sample page with the email addresses in reverse to stop spam. I have the htm document, and the js document. I don't want to post the htm document, but what I used in the email space and in the header:

    Header:

    <script src="spam.js" type="text/javascript" >
    </script>


    in email cell:

    <script type="text/javascript">
    emLink("epohr", "ude.ortsa.uwm");
    </script>


    Here is the js file:

    The reverse function was already created but the additional code I had to create. I got up to the mailto link and just cannot seem to get the code right. Everytime I try to run the htm I get an error inthe debugger - well I know that, but the email function within the mailText is so messed up:

    */


    function stringReverse(textString) {
    if (!textString) return '';
    var revString='';
    for (i = textString.length-1; i>=0; i--)
    revString+=textString.charAt(i)
    return revString;
    }


    function


    /*
    Function emLink to reverse faculty's
    email address

    Variables
    rname: name in reverse order
    rserver: value of the server parameter in reverse
    email: name of faulty and the server name
    mailText: email variable

    */

    function emLink(name, server) {
    var rname=stringReverse(name);
    var rserver=stringReverse(server);
    var email="rname@rserver";
    var mailText=('<a href="mailto:' + email + '">' + email + '</a>');

    return mailText;

    }

    Thank you in advance for any assistance! I am a newbie in javascript - as if you didn't already know.

  • #2
    Regular Coder mjlorbet's Avatar
    Join Date
    Jan 2008
    Location
    Milwaukee, WI
    Posts
    724
    Thanks
    8
    Thanked 96 Times in 95 Posts
    mailto is more of an html topic, it's been getting asked about a lot lately too. the mailto: prefix is, and has been for some time, deprecated. the best results you'll get from this is to open the default e-mail editor on the user's system. if you're hoping to send an e-mail from your page, you'll be best served to use ajax along with a server-side mailer script so that your page doesn't even need to reload to send the message.

    as far as the error you're getting (in case the behavior i described is actually what you're trying for) is likely coming from references to mailText, rname, rserver, and email outside of the emLink function (can't be sure, don't have enough source for that). since they are declared within the scope of the emLink function, they don't exist outside of that function. if you need to declare them within the function use the convention
    Code:
    window["rname"]=...
    which will create the variable in the scope of window (global in regards to javascript). there really shouldn't be a reason to have to declare them inside the function though instead of just setting them. just put
    Code:
     
    var rname, rserver, email, mailText;
    just inside the opening script tag (or the top of the file if you're using an external js) and remove the keyword var from in front of the names of your variables inside the emLink function
    -Mike
    "Want me to precludify him, like some kind of dispatcherator?... Can do!" -Bender

  • #3
    New to the CF scene
    Join Date
    Apr 2008
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Not quite what I was looking for.....

    I should have prefaced everything I said with "I am a student", and I have to do it a certain way, and not using outside coding other than the htm doc and the external js. I will attach both my docs that I am using. I know how to do it with adding all the link stuff. Like dates and numbers. What the textbook part we are in is the "working with javascript". Thank you - I am not "cheating" just out for resources - this is the worst textbook I have ever used. I know about the deprecated items, but, the book we are working with is last published in 2006.

    Thanks!
    Attached Files Attached Files

  • #4
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    Have you considered what those without js get?

    Fwiw, a growing number of developers feel that email harvesters and the spam which typically results from their visits is the site owner's problem, not the site user's.
    Any techniques used to block or deter email harvesters which impacts negatively on the basic usability of that email link isn't worth using, imo.

    I appreciate what you're trying to avoid, but making the email link unusable to a certain &#37; of users* isn't a good solution, again, imo.

    (* general stats vary, but often report 5-10% of users w/o js-enabled browsers. There are a number of reasons why a user's browser might not be js-enabled. It's not always simply the case that a user has a browser which can support it, but has chosen to disable it.)


    So, imo, leave the email link au-naturelle and set up some good server-side and email client-side filters.

    As a side note, I'd suggest adding a contact form as users may not always be visiting your site on a machine which has their email accounts set up. A contact form would give them the means to contact the site owner/whomever without needing to have their email account set up in an email app or to copy/paste the address into a web mail page.

  • #5
    New to the CF scene
    Join Date
    Apr 2008
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    reply to Bill

    Thanks for the input - I understand what you are saying - this was an assignment, not "real". The assignment was to create the jscript to reverse the email address. I am not interested in the ramifications (at this point), only doing the assignment per instructions in my textbook. So, if you have input or assistance in that regard with exactly what I posted (in the file), then that would be much more appreciated. Also in real life I would have added some info about hiding the javascript if the user was unable to use it, then of course it wouldn't matter, and I would have to do something else.

    Typically, I use Dreamweaver, and whatever tool I need to get my final results, not straight HTML, XHTML, Javascript or whatever I will be be using in my class.

    Also, my goal is to be the one who sets up client/server side to protect users from spammers - not necessarily to design a website with that information.

    Thank you!

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,917
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Here is your problem:-

    var email="rname@rserver";

    should be:-

    var email = rname + "@" + rserver;


    BTW, the time to say "thanks" is afterwards, not beforehand which gives the impression that you take other people's unpaid assistance for granted. Or as British politician Neil Kinnock put it, "Don't belch before you have had the meal." Prefer to use "please" beforehand and if you find a response helpful then you can use the "Thank You For This Post" button.

  • #7
    New to the CF scene
    Join Date
    Apr 2008
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    OK - that makes sense for that - I can see why it should be there, as the rname and rserver are the variables - now what about the mailTo where email is the other variable - would both of them, example:

    <a href="mailto:email">email</a>

    that being the regular html code, email being the variable - is it both of them of just the second one? My textbook is non-specific - it just says that email is the variable.

    I made the changes to the email variable

    var email = rname + "@" + rserver;

    and put in this

    var mailText='<a href="mailto:email">email</a>';

    as the mailText variable - I saved it and saved the html document - and I am still getting script errors, it doesn't "show" the email of the person in the table.

  • #8
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,917
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    var mailText=('<a href="mailto:' + email + '">' + email + '</a>');

    results in

    <a href="mailto:rhope@mwu.astro.edu"> rhope@mwu.astro.edu</a>

    What are the script errors you refer to?

  • #9
    New to the CF scene
    Join Date
    Apr 2008
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I am getting this:

    A Runtime Error has occurred.
    Do you wish to Debug?

    Line: 34
    Error: Expected '('


    Line 34 is the first function call:

    <script type="text/javascript">
    emLink("reldac", "ude.ortsa.uwm");
    </script>

    then the others say at their lines and says Error: Object Expected.

  • #10
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,917
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    The trouble is that
    emLink("reldac", "ude.ortsa.uwm");is in a separate script block. Try combining your scripts as follows:-


    Code:
    <script type="text/javascript">
    
    emLink("epohr", "ude.ortsa.uwm");
    
    function stringReverse(textString) {
    if (!textString) return '';
    var revString='';
    for (i = textString.length-1; i>=0; i--)
    revString+=textString.charAt(i)
    return revString;
    }
    
    function emLink(name, server) {
    
    
    var rname=stringReverse(name);
    var rserver=stringReverse(server);
    var email=rname + "@" + rserver;
    var mailText=('<a href="mailto:' + email + '">' + email + '</a>');
    return mailText;
    
    }
    
    </script>

  • Users who have thanked Philip M for this post:

    tinkerbell86440 (04-27-2008)

  • #11
    New to the CF scene
    Join Date
    Apr 2008
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Actually that script:

    emLink("epohr", "ude.ortsa.uwm");

    and 5 others are in a table cell - seperate script block on the htm (look at htm file in the zip file).

    How does putting it in the external js going to help? There are 6 actual script calls. If that was the only I would have even used it in a external js, but in the htm. But, since I cannot, I guess I don't understand.

    (Next time I will know better and take a class such as this in the actual classroom - you and others have given me more information than I will ever get from my online class instructor).
    Last edited by tinkerbell86440; 04-27-2008 at 09:58 PM. Reason: mistake in reading the previous post

  • #12
    New to the CF scene
    Join Date
    Apr 2008
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I just re-read the previous post from Philip - I would put that code under each? of the email address cells? That is a lot - the purpose of the assignment is to 'call' the function from an external js file. I will try it anyway to see how it works.


    rona

  • #13
    New to the CF scene
    Join Date
    Apr 2008
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Philip - I added that last part to the htm file, at each table cell, and didn't seem to make a difference. Well, it did, no errors, but still no visible email addresses in that column of the table.


  •  

    Posting Permissions

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