Google Answers Logo
View Question
 
Q: Tweak javascript to make it work in Netscape 4.7 ( Answered 5 out of 5 stars,   1 Comment )
Question  
Subject: Tweak javascript to make it work in Netscape 4.7
Category: Computers > Internet
Asked by: gan-ga
List Price: $5.00
Posted: 18 Feb 2003 16:33 PST
Expires: 20 Mar 2003 16:33 PST
Question ID: 163202
Tweak javascript to make it work in Netscape 4.7 :

(initially stationary image to slide across horizontally, stop, then
slide along a bit more.)

works in ie6 (or did before anyway ;-)

this might not be possible in Netscape 4.7?


01  <html>
02  <head>
03
04  <script type="text/javascript">
05  <!--
06  var currentPosition=30;
07
08  function slideImageIntoView()
09         
10           {
11           currentPosition++;
12           myimage.style.left = currentPosition;
             if(currentPosition > 127)
               {
               setTimeout("slideImageOutOfView()",5000);
               }
               else
               {
               setTimeout("welcomeMsg()",1);
               }
             }

function slideImageOutOfView()
         {
         currentPosition++;
         myimage.style.left = currentPosition;
         if(currentPosition > 219)
           {
           exit(1);
           }
           else
           {
           setTimeout("slideImageOutOfView()",1);
           }
         }
//-->
</script>

<style type="text/css">
<!--
#myimage{position:absolute;top:12px;left:30px}
-->
</style>

</head>

<body onLoad="slideImageIntoView()">

<img id="myimage" src="someimage.gif" alt="">

<!-- error message in netscape 4.7:

JavaScript Error:
http://mydomain/thisfile.html, line 12:

myimage is not defined. 

-->

</body>
</html>

Clarification of Question by gan-ga on 18 Feb 2003 16:38 PST
line 19: welcomeMsg() should read: slideImageIntoView()

Clarification of Question by gan-ga on 18 Feb 2003 18:33 PST
My latest failed attempt & a page which may help:

http://www.yourhtmlsource.com/javascript/advanceddoms.html#Level1DOM




<html>
<head>

<script type="text/javascript">
<!--
var currentPosition=30;

if (document.getElementById || document.all || document.layers)
{
  if (document.getElementById) {
    alert('Level 1 DOM code');
   }
   else if (document.all) {
    alert('Microsoft DOM code');
   }
   else if (document.layers)
	{


	function slideImageIntoView()
         
		 {
 	         currentPosition++;
        	 window.document.layer1.style.left = currentPosition;
  	         if(currentPosition > 127)
  	           {
        	   setTimeout("slideImageOutOfView()",5000);
     	           }
  	           else
		   {
		   setTimeout("welcomeMsg()",1);
		   }
        	 }

	function slideImageOutOfView()
        	 {
		 currentPosition++;
		 window.document.layer1.style.left = currentPosition;
		 if(currentPosition > 219)
		   {
		   exit(1);
		   }
		   else
		   {
		   setTimeout("slideImageOutOfView()",1);
		   }
		 }


	}
}



//-->
</script>



</head>

<body onLoad="slideImageIntoView()">

<div style="position: absolute; top: 12; left: 30" id="layer1">
<img src="at.gif" alt="">
</div>

<!-- error message in netscape 4.7:

JavaScript Error:
http://mydomain/thisfile.html, line 14:

msg is not defined. 

-->

</body>
</html>

Clarification of Question by gan-ga on 18 Feb 2003 18:37 PST
Doh! still got that wrong function name in there - welcomeMsg() - but
the code's erroring out before that point anyway I think?
Answer  
Subject: Re: Tweak javascript to make it work in Netscape 4.7
Answered By: j_philipp-ga on 18 Feb 2003 20:53 PST
Rated:5 out of 5 stars
 
Hello Gan,

Try the follwing:

-----

<html> 
<head>
<title>Sample</title>

<script type="text/javascript"> 
<!-- 
var currentPosition = 30; 
 
function slideImageIntoView() 
{ 
    currentPosition += 5;
    positionLayer("layer1", 30, currentPosition);
    if (currentPosition < 127)
    { 
        setTimeout("slideImageIntoView()", 60);
    }
    else 
    { 
        setTimeout("welcomeMsg()", 1);
    } 
} 
 
function slideImageOutOfView() 
{ 
    currentPosition -= 5; 
    positionLayer("layer1", 30, currentPosition);
    if (currentPosition > -100) 
    { 
        setTimeout("slideImageOutOfView()", 60);
    } 
}

function positionLayer(lrName, x, y)
{
    if (document.all)
    {
        document.all[lrName].style.left = x + "px";
        document.all[lrName].style.top = y + "px";
    }
    else if (document.layers)
    {
        document.layers[lrName].left = x;
        document.layers[lrName].top = y;
    }
    else if (document.getElementById)
    {
        elem = document.getElementById(lrName);
        elem.style.left = x +  "px";
        elem.style.top = y + "px";
    }
}

function welcomeMsg()
{
    alert("Welcome");
    slideImageOutOfView();
}

//--> 
</script> 
 
</head> 
<body onLoad="slideImageIntoView()"> 
 
<div style="position: absolute; top: 12px; left: 30px" id="layer1">
<img src="at.gif" alt="">
</div> 
 
</body> 
</html>

-----

The image will move down, display the "Welcome" message, then move up
again and out of the browser area. While you might want to change the
behavior, the important function here is "positionLayer". It's a
general function to position a layer and you may want to reuse it for
other JavaScripts as well. It tests the browser's object model to then
go into separate lines for each.

Above HTML has been tested with Netscape Navigator 4.7 [1]. In
general, "document.layer" is used for Netscape 4x, "document.all" for
Internet Explorer and the standard "document.getElementById" for newer
versions of Internet Explorer, as well as the more recent Netscape
versions.


I hope it helps!


Footnotes:

[1] Netscape 4.7 can be found at:

Browser Archive
http://browsers.evolt.org/


Search strategy:
(none)
gan-ga rated this answer:5 out of 5 stars and gave an additional tip of: $5.00
j_philipp, your code does just what I want - thank you very much; I'd
become rather frustrated with this!

Comments  
Subject: Re: Tweak javascript to make it work in Netscape 4.7
From: j_philipp-ga on 19 Feb 2003 01:08 PST
 
Gan, thanks for the nice rating & tip -- good luck with future coding!

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy