Beginning JS Basics questions

Oh, I got that from before from the link but I am still trying to see or have an idea of what it looked like just for the knowledge, just because something is obsolete doesn’t mean I don’t wish to know about it. Even when I started studying the A+ exams for my pc repair career back in the 90s and they referred to computer stuff back in the 80s, I still wanted to know what they were talking about, just out of curiosity or to have the knowledge.

Alright, I’ll keep searching the net to see if I can get a screenshot of what this is about, thanks for help as always, be in touch with other issues as I go along!

The links bar you might also know of as the bookmarks toolbar, or favorites bar.
See: Internet Explorer- Links bar

PERFECT! understood, thanks!

This is an entire script, can anyone tell me exactly why it is not opening the new window please?


<!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" lang="en" xml:lang="en" >
<head>
<meta http-equiv="Content-type" content="text/html; charset=ISO-8859-1" />
<title>FunKaDeLic</title>
<link type="text/css" rel="stylesheet" href="funkadelic.css" />

<SCRIPT type="text/javascript" >

function openindex ()
{

var name=prompt("What is your name?","Write it here")

var OpenWindow=window.open("", "newwin", 
"height=300,width=300");

OpenWindow.document.write("<HTML>")
      OpenWindow.document.write("<TITLE>")
      OpenWindow.document.write
	   ("Hello " +name+ " Here is your window!")
      OpenWindow.document.write("</TITLE>")
      OpenWindow.document.write("<BODY BGCOLOR=green>")

OpenWindow.document.write("<CENTER>")
      OpenWindow.document.write
	   ("<font size=+1>New Window</font><P>")
      OpenWindow.document.write
	   ("<a href='' onClick='self.close()
	   '>This closes the window</a><p>")
      OpenWindow.document.write("</CENTER>")
      OpenWindow.document.write("</BODY>")
      OpenWindow.document.write("</HTML>")

}
 </SCRIPT>


</head>

<body>   

onLoad="openindex ()"

</body>

</html>

I think one problem was you didn’t have the ending semi-colons on each line…


<!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" lang="en" xml:lang="en" >
	<head>
		<meta http-equiv="Content-type" content="text/html; charset=ISO-8859-1" />
		<title>FunKaDeLic</title>
		<link type="text/css" rel="stylesheet" href="funkadelic.css" />
		<script type="text/javascript" >
			function openindex() {
				var name = prompt("What is your name?","Write it here");

				var OpenWindow=window.open("", "newwin", "height=300,width=300");
					OpenWindow.document.write("<HTML>");
					OpenWindow.document.write("<TITLE>");
					OpenWindow.document.write("Hello " +name+ " Here is your window!");
					OpenWindow.document.write("</TITLE>");
					OpenWindow.document.write("<BODY BGCOLOR=green>");

					OpenWindow.document.write("<CENTER>");
					OpenWindow.document.write("<font size=+1>New Window</font><P>");
					OpenWindow.document.write("<a href='' onClick='self.close()'>This closes the window</a><p>");
					OpenWindow.document.write("</CENTER>");
					OpenWindow.document.write("</BODY>");
					OpenWindow.document.write("</HTML>");
			}
		</script>
	</head>
	<body>

	<script type="text/javascript">
		window.onload = function() {
			openindex();
		};
	</script>
	</body>
</html>

Thanks but why the need for this script in the body?

<script type="text/javascript">

        window.onload = function() {

            openindex();

        };

    </script>

What I am seeing online does not have a script tag in the body, only the

onLoad=“openindex()”

so what doesn’t that work please?

I am pretty sure you mean it to read as:

<body onload="openindex();"></body>

The way I presented allowed the Javascript to be trigged after the rest of the HTML was already loaded, hence “onload”

I think I was missing a key issue, when I was told to place the function “between the Body tags” , I was thinking like this:

<body>

function goes here

</body>

but what I am seeing now is the code needs to go inside the <body> tag like this:

<body ..function goes here>

</body>

Is that correct?

The parenthesis must not be separated from the function name. Not even by a space.


// good
function openWindow() {
    
}
openWindow();

// bad
function openWindow () {
    
}
openWindow ();

// ugly
function openWindow () {
    
}
openWindow();

When there is no function name, the word “function” and the parenthesis should be separated by a space, to help prevent confusion. The name of the function though must still have no separation from the invoking parenthesis.


var openWindow;

// good
openWindow = function () {
    
};
openWindow();

// bad
openWindow = function () {
    
};
openWindow ();

// ugly
openWindow = function() {
    
};
openWindow();

To further break down this script, I don’t see the need for these?

w.write("<HTML>")
w.write("<TITLE>")

I erased them from my script and in the html page everything works fine without them?

Also regarding this:

OpenWindow.document.write("<font size=+4>New Window</font><P>");

What is the <P> for?

Hssss - evil fontses! :goof:

I suspect that the <P> is the author’s well-intentioned but badly maligned attempt to add some vertical spacing inbetween.

Typically today a class name might be applied, so that such presentational things may be controlled from there.

Ok, thanks, please disregard the first part of my question, I had overlooked that this script included an HTML doc.

Studying this section now:

JavaScript Primers #15

This script is working on that page for “Assignment 15”:

<html>
    <head>
    </head>
    <body bgcolor="white">
    <center>
    <h1>Andree Growney</h1>
	<p>
    <a href="" onMouseOver="document.pic1.src='bubble2.gif' "
        onMouseOut="document.pic1.src='bubble1.gif'">
    <img src="bubble1.gif" border=0 name="pic1"></a></p>
    </body>
    </html>

but I am not seeing the image on my html page? I have placed both images and the html page named test.html on my C drive into a folder named “Test”, help?

This is my entire html page:


<!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" lang="en" xml:lang="en" >
<head>
<meta http-equiv="Content-type" content="text/html; charset=ISO-8859-1" />
<title>FunKaDeLic</title>
<link type="text/css" rel="stylesheet" href="funkadelic.css" />

<script type="text/javascript" >
 
 </script>

</head>

 <body bgcolor="white">
    <center>
    <h1>Andree Growney</h1>
	<p>
    <a href="" onMouseOver="document.pic1.src='bubble2.gif' "
        onMouseOut="document.pic1.src='bubble1.gif'">
    <img src="bubble1.gif" border=0 name="pic1"></a></p>

</body>

</html>

Please see attached pic of the Test folder

If you’re testing this in Internet Explorer, have you allowed local scripting?

I was testing in FF Beta 4.0, I just checked with IE, it works, thanks, will look for the setting in FF to allow scripting, the menu is totally different,

Far as I am seeing here Javascript is enabled, see attachment, any idea why I am having this problem please?

You’re using Firefox, right.

Does the error console give you any info?

Sorry Paul, never heard of the “error console” before? Have to sign off now, been a very long day dealing with viruses from 2 pc’s here and trying to study JS at the same time, will check back in the morning, thanks…

Here the menu reference for Firefox 4 so that you can get more info on it.
Menu Reference | How to | Firefox Help