SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: IE to Netscape

  1. #1
    SitePoint Member
    Join Date
    Feb 2001
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I need a way for this script to work under Netscape. I have no problem under IE.
    Thanks
    Mark

    <html>
    <head>
    <script language="JavaScript">
    <!--
    function display()
    {
    heading.innerText = "Test Message"; // will not work **
    }
    //-->
    </script>
    </head>
    <body onload="display()">
    <span id="heading" name="heading"></span>
    </body>
    </html>

  2. #2
    SitePoint Addict Drinky's Avatar
    Join Date
    Jan 2001
    Location
    England
    Posts
    338
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This will solve your problem

    Code:
    <html>
    <head>
    <style type="text/css">
      #heading {position:absolute;}
    </style>
    <script language="JavaScript">
    <!--
    function isNS(){
    	if (navigator.appName == "Netscape"){
    		return true;
    	}else{
    		return false;
    	}
    }
    
    function display(html){
    	if (isNS()){
    		document.heading.document.open();
    		document.heading.document.write(html);
    		document.heading.document.close();
    	}else{
    		heading.innerText = html;
    	}
    }
    //-->
    </script>
    </head>
    <body onload="display('Text Message');return true;">
      <span id="heading" name="heading"></span>
    </body>
    </html>
    Drinky

  3. #3
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Or to cut out the entire ns checking function
    <script language="JavaScript">
    <!--

    var n = (navigator.appName == "Netscape") ? 1:0

    function display(html){
    if (n){
    document.heading.document.open();
    document.heading.document.write(html);
    document.heading.document.close();
    }else{
    heading.innerText = html;
    }
    }
    //-->
    </script>


    Both will work, I just like to condense my code as much as possible.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  4. #4
    JavaScript Guru (Big Ego) Arielladog's Avatar
    Join Date
    Jul 1999
    Location
    SC, USA
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey guys,

    Y'all both forgot about NS 6. Instead, the code should be:

    Code:
    function display(html){ 
      if(document.getElementById){
        document.getElementById("heading").innerHTML=html;
      }else if(document.all){
        document.all["heading"].innerHTML=html;
      }else if(document.layers){
        with(document.layers["heading"].document){
          open();write(html);close();
    }}}
    aDog

  5. #5
    SitePoint Addict Drinky's Avatar
    Join Date
    Jan 2001
    Location
    England
    Posts
    338
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I didn't forget about netscape 6, i was tracking down how do it but you go there first. Cheers for that i can stop looking now
    Drinky

  6. #6
    SitePoint Member
    Join Date
    Feb 2001
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the help everyone.

    Mark


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
  •