Need help getting Javascript to work under IE8

Discussion in 'HTML & Website Design' started by Kai2810, Jan 10, 2010.

  1. #1
    Kai2810, Jan 10, 2010 IP
  2. ayushdeepsingh

    ayushdeepsingh Member

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #2
    Hey Remove all Old Float Java script and html from page and try this
    this one is easy and good work in every browser ;)

    <div id="floatdiv" style="
    position:fixed;
    width:200px;height:50px;
    left:500px;
    top:50%;
    padding:16px;background:#FFFFFF;
    border:2px solid #2266AA">


    This is a floating javascript menu.
    <button Onclick="document.getElementById('floatdiv').style.display='none'">Hide</button>


    </div>

    Enjoy!
     
    Last edited: Jan 11, 2010
    ayushdeepsingh, Jan 11, 2010 IP
  3. Kai2810

    Kai2810 Active Member

    Messages:
    68
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #3
    Hi ayush,

    LOL that was a great idea, using position:fixed.

    but again it's working in FF, but not in IE!! The floating div block is stuck in wherever the code is in html....
    www.thienkaiwei.com/contactus8e1.php
     
    Kai2810, Jan 11, 2010 IP
  4. meameajones

    meameajones Peon

    Messages:
    55
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Ditch IE8 and go for FF
     
    meameajones, Jan 11, 2010 IP
  5. ayushdeepsingh

    ayushdeepsingh Member

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #5
    You Should Replace your first line from document <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

    TO
    \/
    \/
    \/
    \/
    \/
    \/
    \/
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    Enjoy !
     
    ayushdeepsingh, Jan 11, 2010 IP
  6. Kai2810

    Kai2810 Active Member

    Messages:
    68
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #6
    Okay I just tried that and it works.

    BUT...yes another but...my client's table based layout is screwed up. The tables are really kinda messy, will have to sort it out.
    thienkaiwei.com/contactus8e.phphttp://thienkaiwei.com/contactus8e.php

    Let's see if I can correct this.
    Thanks again Ayush.

    jones...that's not a good idea when most of my client's customers are 45+ year olds who probably symbolize IE as the internet.
     
    Last edited: Jan 11, 2010
    Kai2810, Jan 11, 2010 IP
  7. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Yeah you've been building your whole website (did you say table-based layout???? how little are these people paying you?) in Quirks Mode, meaning, you've been building the site to work with IE5.5 : )

    ayushdeepsingh gave you wonderful advice (except I'd go further and say Use Strict) but now you see what has been hidden from you all along.

    IE has the greatest visible differences between Quirks Mode (bad/no doctype) and Standards Mode (good doctype) but the other browsers also have a sub-standards or quirks mode as well.

    Start recoding the layout to make it look good in the browsers NOW because now you're coding in standards mode.

    As additional pointers, don't start your scripts right after the HTML tag... put the required tags in there first: the meta tag stating what your document's MIME type is
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    and the title.
    
    <script language="JavaScript">
    	var message = "Copyright © My Drum School Singapore. All Rights Reserved. "; 
    	function rtclickcheck(keyp){ if (navigator.appName == "Netscape" && keyp.which == 3){ 	alert(message); return false; } 
    	if (navigator.appVersion.indexOf("MSIE") != -1 && event.button == 2) { 	alert(message); 	return false; } } 
    	document.onmousedown = rtclickcheck;
    </script>
    
    Code (markup):
    language=javascript has been deprecated for quite some time now. One of the benefits of having a strict doctype (instead of a transitional one) is that the HTML Validator can tell you that you've got an error so you know to fix it.
    if (navigator.appName == "Netscape"... seriously, what browser are you building for? Do you actually know someone who has a copy of Netscape? Even I don't know where to get a copy. appName's are changed by users anyway: Opera users set theirs to "MSIE" and Firefox users can set theirs to whatever... in fact most browsers if not all can. And what if someone's using an iPhone? That's Safari, but I don't see "webkit" anywhere in that script. And if it checked for version numbers, it would think Opera 10 was Opera 1, as it seems all the current sniffers who look at browser versions only expect a single digit. Lawlz.
    For this reason and others, good javascript doens't usually bother checking the appName but just asks if the browser can do "x", and if it can then it goes through the script, and if it can't you can offer something else, or Javascript isn't supported at all. This is called "object detection" or "feature detection" which is more reliable.

    Actually they do this in the floating example you posted:
    
         menu:  
           document.getElementById  
             ? document.getElementById(floatingMenuId)  
            : document.all  
              ? document.all[floatingMenuId]  
              : document.layers[floatingMenuId]  
    };
    
    Code (markup):
    Here it just checks what exists: document.getElementById(id) which is the w3c way most modern browsers use
    or document.all which is IE though Opera does or used to use this
    or
    document.layers which I think was a Mac safari/etc thing. It looks kinda old though:
    
     // Handle Opera 8 problems  
    
    Code (markup):
    That's nice, but in general Opera users are more awesome than IE users: they upgrade : ) We're at Opera 10 now.

    ayushdeepsingh's position: fixed solution is also cool because people who DON'T have javascript will also have the menu always in place! Which is cool... except IE6 can't do position: fixed, so you'd need to give that browser position: absolute and hope the users have Javascript enabled.
     
    Stomme poes, Jan 12, 2010 IP
  8. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #8
    Oh lord that site's BAD. Here's a tip, don't use javascript for that. That's CSS' job.

    Here's another tip, if you have 7k of content in your html before you even GET to the first actual CDATA, you probably are screwing up somewhere. If between the opening of <body> and your first CDATA you have 2.3k of markup, you HAVE screwed up... If your menu doesn't work flash disabled, you've screwed up. If you have 195 validation errors you don't even have HTML, you have complete gibberish - If you have 13 tables on a layout that DOESN'T EVEN HAVE COLUMNS...

    I pity whoever's website that's going to be.

    Throw it out, start over, there is NOTHING on that entire page even worth trying to save.
     
    deathshadow, Jan 12, 2010 IP
  9. ayushdeepsingh

    ayushdeepsingh Member

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #9
    Your welcome ! :)
     
    ayushdeepsingh, Jan 12, 2010 IP
  10. Kai2810

    Kai2810 Active Member

    Messages:
    68
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #10
    Kai2810, Jan 31, 2010 IP