1

What I want to do is pretty simple. Above my blog I want to have a text paragraph with an explanation of the site. However I do not want it to be at the top of every page on the site ONLY the index page. My host has a very restrictive format. I've already asked them for help and it isn't possible with their editor. I cannot edit all of the html but I can change some. Javascript seems to be allowed so I have been trying things like:

<SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">
<!--
if (url==http://mysiteaddress/index.html)
   {document.write('Welcome to my site')}
  //-->
</SCRIPT>

Taking out the if statement, it successfully writes 'Welcome to My site'. So I'm wondering what is wrong with the if statement. I've also tried adding an 'else' in order to see output on any page but have not had any luck.

I obviously don't know much yet so any help would be appreciated. Thanks!

2 Answers 2

2

The url is available via location.href - not sure why you think url exists.

Besides that, mime types are lowercase and the language attribute is obsolete. So use <script type="text/javascript">.

Additionally it'd be better if you didn't use the infamous document.write but document.getElementById('someDiv').innerHTML = 'your html here';

Or get jQuery and simply write $('#someDiv').html('your html here');

Sign up to request clarification or add additional context in comments.

9 Comments

Because I didn't know any javascript. ;) Thanks very much, that will help me off to a good start!
In that case please start with jQuery. You will write much better code as stuff you find in the web that uses jQuery is unlikely to use ancient techniques. Oh, and did I mention that jQuery is awesome?
no no no i'm sorry ThiefMaster there is no better start than with JavaScript then when u know JavaScript for good start using libraries , libraries at the beginning cant build your client side concept as well as JavaScript pure
I don't think you should have to deal with browser-specific issues when learning a language. And JavaScript+jQuery is still JavaScript. You just get some methods wrapping the ugly DOM stuff - and knowing the DOM methods has nothing to do with knowing JavaScript.
Any idea what I'm doing wrong here? Still having problems: <script type="text/javascript"> if (location.href == 'http:\/\/planeth.weebly.com\/index.html') document.getElementById('{intro}').innerHTML = '{Second Life blah blah blah}';</script> <div id="intro"></div>
|
1

Just to add, you can prepend an element to the body element like this:

var p = document.createElement("p");
p.innerHTML = "I am a paragraph";
document.body.insertBefore(p, document.body.firstChild);

You can try it here.

Reference: https://developer.mozilla.org/En/DOM/Node.insertBefore

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.