SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Dec 2010
    Location
    Southeast Michigan
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Code not working in IE8!

    hey guys,

    im having trouble with some javascript code in one of my homework assignments. The code works fine in other browsers except internet explorer 8. The javascript is a email scrambler so email harvesters can't steal the emails. The code is split up between two files. Most of the code is in my html file and part is inside the spam.js file.

    The weird thing is this code works in firefox, chrome, safari and opera. But not internet explorer 8. I haven't tested the code in older versions of IE, but im guessing that it wont work there either.

    Code HTML4Strict:
    <?xml version="1.0" encoding="UTF-8" ?>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
     
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
       <title>Monroe Public Library</title>
       <link href="mplstyles.css" rel="stylesheet" type="text/css" />
       <script type="application/javascript" src="spam.js"></script>
     
    	<script type="text/javascript">
     
    	function showEM(userName, emServer) {
     
    		/* 
    			The showEM() function displays a link to the user's 
    			email address.
    			The text of the user and e-mail server names are entered in 
    			reverse order to thwart e-mail harversters.
    		*/
     
    		userName = stringReverse(userName); // reverse the text of the userName paramater
    		emServer = stringReverse(emServer); // reverse the text of the emServer paramater
     
    		var emLink = userName + "@" + emServer; // combine the text of userName and emServer
    		document.write("<a href='mailto:" + emLink + "'>");
    		document.write(emLink);
    		document.write("</a>");
    	}
     
    	</script>
    </head>
     
    <body>
    <div id="pageContent">
     
    <div id="head"><img src="mpl.jpg" alt="Monroe Public Library" /></div>
     
    <div id="links">
       <span>Quick Links</span>
       <a href="#">Home Page</a>
       <a href="#">Online Catalog</a>
       <a href="#">Friends of MPL</a>
       <a href="#">New Books and Other Good Reading</a>
       <a href="#">Ohio Virtual Library</a>
       <a href="#">Internet Public Library</a>
       <a href="#">Services and Collection</a>
       <a href="#">Adult Programs</a>
       <a href="#">Teen Central</a>
       <a href="#">Children's Room</a>
       <a href="#">Computers at MPL</a>
       <a href="#">Computer Rules and Procedures</a>
       <a href="#">Staff Directory</a>
       <a href="#">Library Records</a>
    </div>
     
    <div id="main">
       <h2>Staff Directory</h2>
     
       <table border="1" cellpadding="5" cellspacing="0">
          <tr>
             <th>Name</th>
             <th>Phone</th>
             <th>E-Mail</th>
          </tr>
     
          <tr>
             <td>Catherine Adler<br />Library Director</td>
             <td>555-3100</td>
             <td>
             <script type="text/javascript">
    		 	showEM("reldac", "vog.lpm");
             </script>
             </td>
          </tr>
          <tr>
             <td>Michael Li<br />Head of Adult Services</td>
             <td>555-3145</td>
             <td>
             <script type="text/javascript">
    		 	showEM("ilekim", "vog.lpm");
             </script>
             </td>
          </tr>
          <tr>
             <td>Kate Howard<br />Head of Technical Services</td>
             <td>555-4389</td>
             <td>
             <script type="text/javascript">
    		 	showEM("drawohk", "vog.lpm");
             </script>
             </td>
          </tr>
          <tr>
             <td>Robert Hope<br />Head of Children's Services</td>
             <td>555-7811</td>
             <td>
             <script type="text/javascript">
    		 	showEM("epohr", "vog.lpm");
             </script>
             </td>
          </tr>
          <tr>
             <td>Wayne Lewis<br />Circulation Services Supervisor</td>
             <td>555-9001</td>
             <td>
             <script type="text/javascript">
    		 	showEM("siwelw", "vog.lpm");
             </script>
             </td>
          </tr>
          <tr>
             <td>Bill Forth<br />Interlibrary Loan</td>
             <td>555-9391</td>
             <td>
             <script type="text/javascript">
    		 	showEM("htrofb", "vog.lpm");
             </script>
             </td>
          </tr>
       </table>
    </div>
     
    <address>
       <b>Monroe Public Library</b>
       580 Main Street, Monroe, OH &nbsp;&nbsp;45050
       <b>Phone</b>(513) 555-0211  
       <b>Fax</b>(513) 555-0241
    </address>
     
    </div>
     
    </body>
    </html>


    Spam.js code:

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

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,682
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    application/javascript is causing you the trouble.

    Strictly speaking it's correct, but IE is way behind the times. IE doesn't even do XHTML, only a fake version of it that it interprets as if it were HTML.

    Change application/javascript to text/javascript and you should be fine.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Member
    Join Date
    Dec 2010
    Location
    Southeast Michigan
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Man you really are the javascript guru. Thank You! That solved my problem.


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
  •