AndrewSmith Posted September 14, 2013 Share Posted September 14, 2013 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? Link to comment Share on other sites More sharing options...
Labtec Posted September 14, 2013 Share Posted September 14, 2013 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. Link to comment Share on other sites More sharing options...
davej Posted September 15, 2013 Share Posted September 15, 2013 (edited) 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 September 15, 2013 by davej Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now