/    Sign up×
Community /Pin to ProfileBookmark

Can not see javascript?

I am new to javascript and am building my first website, after having the content of the website typed up and styled with html and css, I wanted to practice writing a simple javascript code to it. The purpose of the javascript is to repeat on all the pages the copyright information for my website. (the simplest of all codes I believe….) anyways, I post this code to my <div id=”footer”> section.

<script type=”text/javascript”
document.write(copyright);
</script>

I also have the page linked to the external .js file. This files holds …
<script type=”text/javascript”>
var copyright=’blah blah blah’;
document.write(copyright);
</script>

Now when ever i reload Firefox to view the change to make sure the code works, my footer section of the page that is supposed to hold the copyright is blank… Its almost as if the code worked.. But it isn’t displaying, I checked the settings, and yes javascript is enable on my browser, I can go and visit javascript enabled websites and view everything just fine.
Any ideas on why the code is not displaying my information?
Thanks!

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@JMRKERMay 11.2013 — You can not use "document.write('anything')" after the page has been rendered.

If you do, the page is reloaded.

Use a <footer id="footerTag"></footer> in the body

and then, just before the </body> tag place a script

<script type="text/javascript">

var copyright='blah blah blah';

document.getElementById('footerTag').innerHTML = copyright;

</script>
Copy linkTweet thisAlerts:
@tsidebottom10authorMay 11.2013 — I'm afraid I do not understand. If I am correct <footer></footer> is html5, the webpage I am building I have a doctype of 4.01 transitional. What I am wanting to do is a repeating variable, I think. I read about it in a javascript tutorial. And from what it explained, you can make an external JS file with a var equaling to a string of text, having it be what ever you want. Then all you have to do is place document.write(var name) into where you want to display that text in your page. The tutorial mentioned nothing of the footer id and getelementByID that you mentioned. I want to do this because I have the copyright information at the bottom of every page, and if I want to change it in the future, I do not want to have to go to every page and change it, I want to be able to change that one JS file so that then, every page information is changed automatically.

Thank you for the reply by the way. Do you think you could clarify a little more?
Copy linkTweet thisAlerts:
@JMRKERMay 12.2013 — So instead of the <footer> tag pair, use a <div> tag pair instead.

Then create an external file named, for example, that contains your copyright information:

footerInfo.js
<i>
</i>var copyrightedby = 'tsidebottom10';


Then consistently give an id= for each page you wish the footer to be displayed, as in:
<i>
</i>&lt;!doctype stuff...&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt; Whatever &lt;/title&gt;
&lt;script type="text/javascript" src="footerInfo.js"&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
...

&lt;div id="footerTag"&gt;&lt;/div&gt;
&lt;script type="text/javascript"&gt;
window.onload = function() { document.getElementById('footerTag').innerHTML = copyrightedby; }
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@007JulienMay 12.2013 — In this case, it's possible to use document.write (the document is not closed).

But you have at first to load the script which define the variable copyright (a HTML string).

An example of simple script [I]copyrigth.js[/I] (which update the year).
[CODE]// JavaScript Document
var copyright="<p>&copy; "+new Date().getFullYear()+"</p>";[/CODE]


Then, your script should be placed in the footer with something like this :

[CODE]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="generator" content="PSPad editor, www.pspad.com">
<title></title>
[COLOR="#0000FF"]<!-- Load the script -->[/COLOR]
<script type="text/javascript" src='copyright.js'></script>
<style type="text/css">
#footer {font-size:small;text-align:center;}
</style>
</head>
<body>
<div>
<p>Good luck</p>
<div>
<div id="footer">
[COLOR="#0000FF"]<!-- Insert the variable copyright in the footer -->[/COLOR]
<script type="text/javascript">
document.write(copyright);
</script>
</div>
</body>
</html>
[/CODE]
×

Success!

Help @tsidebottom10 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.21,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...