Jump to content

Recommended Posts

I am having trouble with the onload attribute of the <body> of my page. I am not well experienced with this. I am trying to use onload to load a cookie when someone loads the page, all the cookie does is remembers there name. But it is nice so I want to apply it anyway. Here is what I am trying to do.

 

<link rel="javascript" type="text/javascript" href="Cookie.js"/>

<body onLoad="getCookie();setCookie();checkCookie();" vlink=red link=blue text=grey>

 

The functions getCookie();setCookie();checkCookie(); are in Cookies.js, but they wont work. Does anyone know if I can even do this? and if so than can you help me?

Share this post


Link to post
Share on other sites

Good morning Andrew.

 

To load in external Javascript files, you need to use the <script> tag in the <head>.

 

Like this:

 

<script type="text/javascript" src="Cookie.js"></script>

 

That only works if the Cookies.js is inside the same directory as the HTML files.

 

Kind regards,

 

Lab.

Share this post


Link to post
Share on other sites

As Lab says, your external reference is wrong, but also you're using an obsolete approach. Try...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <head><meta charset="utf-8"><title>Title</title><style type="text/css">a:link{color:blue;}a:visited{color:red;}a:hover{color:orange;}a:active{color:black;}body{color:grey}</style><script type="text/javascript" src="Cookie.js"></script><script type="text/javascript">window.onload = init;function init(){getCookie();setCookie();checkCookie();}</script></head><body></body></html>

The above is for HTML4.01. It can be made much simpler in HTML5.

Edited by davej

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...