problem with Javascript code from Include

Discussion in 'Javascript' started by Tony Strazzeri, May 16, 2005.

  1. Hi all,

    I a fairly new to html and Javascripting. I have been trying to write
    some code to hide my email address from spam harvesters. I copied the
    code from various web examples and modified it to suit me.

    The code to generate the address is in a js include file. I am using
    frontpage 2003 to create my web pages. My problem is that the code
    works OK when I test it using Frontpage's 'Preview' but does not work
    when I display the page in an actual browser (IE or Firefox).
    The same code works OK if I have it inline but not when I place the
    code in an include file.

    Can someone tell me what I am doing wrong?

    The include file is is called 'email_addy.js' and is stored in a folder
    called 'scripts/' off the page root.

    The javascript code for the include is below. The html for the page
    follows it.

    Cheers
    Tony.

    '========start [email_addy.js] ==========
    function address_from_addy(myUserName, mySubject )
    {
    var myAddress ="";
    var myDomainNamePrefix = "winbusiness";
    var myDomainNameType="com";
    var myDomainNameLocation="au_address_from_addy";
    var strDisplayTip=""
    var atString = "^@^@^";
    atString = atString.slice(1,2);
    myAddress =myUserName + atString ;
    myAddress =myAddress + myDomainNamePrefix + "." + myDomainNameType +
    "." + myDomainNameLocation ;
    strDisplayTip=myAddress
    if ( mySubject ){myAddress = myAddress + '?subject=' + mySubject };
    else {myAddress = myAddress};
    document.write('<a href=\"mailto:' + myAddress + '\">' + strDisplayTip
    + '</a>');
    window.status=strDisplayTip ;
    }
    '======== end [email_addy.js] =============


    '======== start page html ===============
    <html>
    <head>
    <script src="\scripts/email_addy.js" type="text/javascript"></script>
    <script>
    function generate_address(myUserName, mySubject )
    {
    var myAddress ="";
    var myDomainNamePrefix = "myDomainName";
    var myDomainNameType="com";
    var myDomainNameLocation="au_address_from_inline";
    var strDisplayTip=""
    var atString = "^@^@^";
    atString = atString.slice(1,2);
    myAddress =myUserName + atString ;
    myAddress =myAddress + myDomainNamePrefix + "." + myDomainNameType
    + "." + myDomainNameLocation ;
    strDisplayTip=myAddress
    if ( mySubject ){myAddress = myAddress + '?subject=' + mySubject };
    else {myAddress = myAddress};
    document.write('<a href=\"mailto:' + myAddress + '\">' +
    strDisplayTip + '</a>');
    window.status=strDisplayTip ;
    }
    </script>
    </head>
    <body>
    Address using include: mailAddyMarker[myEmail]
    <script language="javascript" type="text/javascript">
    <!--
    // The parameters for this are: Username,myDomainNamePrefix,
    // Note: the order of these two is reversed from usual practice
    // myDomainNameLocation,myDomainNameType
    address_from_addy( "myEmail")
    //-->
    </script>
    <!-- End: email address block -->
    <hr>
    Address using inline call: mailAddyMarker[myEmail]
    <script language="javascript" type="text/javascript">
    <!--
    // The parameters for this are: Username,myDomainNamePrefix,
    // Note: the order of these two is reversed from usual practice
    // myDomainNameLocation,myDomainNameType
    generate_address( "myEmail")
    //-->
    </script>
    <!-- End: email address block -->
    <hr>
    </body>
    </html>
    '======== End page html ===============
    Tony Strazzeri, May 16, 2005
    #1
    1. Advertising

  2. Tony Strazzeri

    SCDeveloper Guest

    Check the path of the include file. Try <script
    src="scripts/email_addy.js" type="text/javascript"></scrip­t>.
    The javascript is not big, why not copying it to start_page.html?

    SCDeveloper
    http://www.sharingcorner.com
    SCDeveloper, May 16, 2005
    #2
    1. Advertising

  3. Hi,

    Thank you both for your response.

    I have tried various combinations of the path and done the edits in
    notepad then used ftp to transfer the edited file.

    putting a dot before the first slash seemed to do the trick
    <script src="./scripts/gen_email.js" type="text/javascript"></script>

    Funny though... I am sure I had already tried that.
    I also made the change using Frontpage and used it to upload the pages
    and that still worked.

    BTW.
    I know it was a small amount of code and it could have been placed
    directly into each page, but I was using the code in several pages
    (some of which were in nested folders). So I wanted to keep it in one
    location.

    I still wanted toi see how to deal with this in case I needed to use
    the technique in the future.

    Thanks both.

    Tony.

    PS now I have another question, but I'll post it separately it's to do
    with putting a marker on the page visible at design time and have it
    replaced by the address at runtime.
    Tony Strazzeri, May 17, 2005
    #3
  4. [stripped X-Post to microsoft.public.frontpage
    since no such group exists on this server]

    Tony Strazzeri wrote:

    > I have tried various combinations of the path and done the
    > edits in notepad then used ftp to transfer the edited file.
    >
    > putting a dot before the first slash seemed to do the trick


    Yes, it *seems to be* that way. However, it *is* not so.

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

    ^^ ^^^^^^^^^^^^
    If you would care to compare with the original version:

    | <script src="\scripts/email_addy.js"
    ^ ^^^^^^^^^^
    | type="text/javascript"></script>

    > Funny though...


    Not at all.

    > I am sure I had already tried that.


    You have not only put a dot before the first slash but you have also turned
    a wrong backslash into the correct forward slash. The dot-slash, however,
    is completely unnecessary (and should not change anything, else your server
    is definitely borken) as it only specifies the source document path.

    > PS now I have another question, but I'll post it separately it's to do
    > with putting a marker on the page visible at design time and have it
    > replaced by the address at runtime.


    Are you also going to tell us what you are going to do next week?


    PointedEars
    Thomas 'PointedEars' Lahn, May 23, 2005
    #4
  5. Tony Strazzeri

    Randy Webb Guest

    Thomas 'PointedEars' Lahn wrote:
    > [stripped X-Post to microsoft.public.frontpage
    > since no such group exists on this server]


    Then why did you set follow-up to a group that does not exist "on this
    server" ?

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    Randy Webb, May 24, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Danny Anderson
    Replies:
    5
    Views:
    487
    Victor Bazarov
    Aug 15, 2003
  2. Rolf Magnus
    Replies:
    2
    Views:
    591
    Karl Heinz Buchegger
    Nov 28, 2003
  3. Elie Nader
    Replies:
    1
    Views:
    626
  4. web4all
    Replies:
    0
    Views:
    3,120
    web4all
    May 11, 2006
  5. Andreas Bogenberger
    Replies:
    3
    Views:
    889
    Andreas Bogenberger
    Feb 22, 2008
Loading...

Share This Page