DHTML

Mellor: DHTML - Learning by Example.

FAQs

Question

Comment

I want to date-mark my HTML files so people can see when the last update was, is there an automatic way of doing this ?

The best way is to have an onLoad event handler in the BODY statement calling a function, which in turn contains:

document.write("updated on " + document.lastModified)

or similar.

How can I put page breaks in HTML sides ?

You do that by setting up a class of page breaks.
You can set up the class on any HTML command, but I think the best method is to set up the class within a BR or P tags. That way there's some white space where the page can break. Here's a look at the format (this will sit between your flags):

<STYLE TYPE="text/css"> P.breakhere {page-break-before: always} </STYLE>

This then will be the activator for the page break:

<P CLASS="breakhere">

You can set up as many different classes as you'd like as long as you keep following the same format as above (or similar).

I'm having trouble with pop-up boxes. How do I open new windows of a certain size? At the moment I'm using HTML code <target="_blank"> and trying to specify the new windows size in the new HTML document.

Older browsers will not recognise the "resize" method, so use "open" instead. Write a function in HEAD thus:

function box(URL)

{window.open(URL,'box','menubar=yes,status=no,resizable=yes,scrollbars=yes,width=30,height=20')}

and call it using:

<a href="javascript:box('file.htm')">open file</a>

But remember you can only call the function "box" once, meaning you can only have one new window open at a time. If you want several, you will have to repeat the function (name it box2) and call it using:

<a href="javascript:box2('file2.htm')">

Apparently some people keep visiting HTML files which should properly be viewed in frames. Is there a way to fix this ?

If your visitors are in a frame then you can use "location", like:

parent.contents.location="menu.htm"

but if your visitors are totally outside of the frame then a little more force has to be used, the most elegant way is to use an IF statement to compare "self" to "parent" and use the outcome to refresh to a different URL:

if (self==parent){
document.write('<meta HTTP-EQUIV=Refresh CONTENT=1;URL=http://www.fbeedle.com target=_top>')};

Note that this code must be in HEAD

Is there any way I can "count-down" a clock on a page ?

Look at the following code, calling "startclock" sets a loop running that clears timeout, displays the current time, and set timeout to re-display the time in 2 seconds. Use it as inspiration, it should contain all the ingredients you need, but find your own answers.

var timerID=null;
var timerRunning=false;
function stopclock()
{if(timerRunning) clearTimeout(timerID);
timerRunning=false;}
function startclock(){
stopclock();
showtime();}
function showtime(){
var now=new Date();
document.clock.face.value=timeValue;
timerID=setTimeout("showtime()", 2000);
timerRunning=true;}

Can I use a Prompt box in connection with a hyperlink to ask visitors if they really want to visit that link ?

Of course, but perhaps a Confirm box is better, and open a new window, to make it easy for your visitor to return:

If (confirm("are u sure") {
sesame = window.open("http://www.fbeedle.com", "books")}

What is VBS ?

VBS stands for Visual Basic Script and is not used client-side on the Internet.

VBS should not be confused with VBScript.

VBS can start, use, and shut down PC applications without client (user) knowledge. If you receive uninvited VBS files (the extension is vbs; e.g. fileName.vbs) by mail or embedded in HTML files, then you should immediately delete them as they can easily be malicious programs or virus's.

What is IP ?

Internet Protocol. The low-level part of the TCP/IP protocol. IP assembles the packets, adds address information and dispatches them over the network. IP has nothing directly to do with DHTML.

I cannot call functions in external files

The newer browsers, MS Internet Explorer 5.5 and Netscape6, do not wait to read in whole external files, so:

<SCRIPT SRC="FileWithFunctionIn.js">
externalfunction()
</script>

may well not work in these browsers. The work-around is to divide them such that the browser pauses and reads in the code before continuing to the next block:

<SCRIPT SRC="FileWithFunctionIn.js">
</script>
<SCRIPT language="JavaScript">
externalfunction()
</script>

Is there any way of getting the "Object" tag to work in Netscape.

Not precisely, but you can combine the Object and Embed tags:

<object classid="" height="" width="">
<!-- parameters here -->
<embed src="" height="" width="">
<noembed>
<img src="default.gif">
</noembed>
</embed>
</object>

So if neither the Object tag nor the Embed tag works in that browser, then at least a default image is shown instead.

In Example R the classID registry value for ActiveX was given, are there any more useful classIDs ?

Sure:

ActiveX:

CLASSID="CLSID:333C7BC4-460F-11D0-BC04-0080C7055A83"

Flash:

CLASSID="CLSID:D27CDB6E-AE6D-11cf-96B8-444553540000"

Shockwave:

CLASSID="CLSID:166B1BCA-3F9C-11cf-8075-444553540000"

RealMedia:

CLASSID="CLSID:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA"

Class ID is most often assigned by the developers computer when the control is first created. They are managed partly through the Windows registry, and are thus difficult to see and manipulate. However you can find out more by using special tools, such as the Microsoft OLE/COM Object Viewer. The Viewer is distributed with the Windows NT Resource Kit - see http://www.microsoft.com/resources/oleview.asp




Return to overview