FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Force javascript to write codes into <body> ?





Summer
Is there a way to write something AFTER <body> tag . I need this because I was given permission to edit the <head> ONLY . It is used for Friendster profile . I wanna add a button to my profile page . Is there any way ?

IF CAN , I WANT :

I CAN CHOOSE WHERE I WANT THE SCRIPT TO GO . MAYBE AFTER eg: <br clear="all" />
Vrythramax
try the document.write function in Javascript, it can be used anywhere within the <body>, I don't think you can call for images with it tho...I could be wrong tho Confused
Summer
I want to type the code in the <head> section cause I can edit the <head> part only . And document.write() can call images . Very Happy
SystemWisdom
You can use the DOM of javascript to do what you want. DOM = Document Object Model.

Here is a simple sample script I wrote up quick:
Code:

<html>
<head>
<title></title>
<script language="javascript" type="text/javascript"><!--
function a()
{
    var p = document.createElement('p');
    var text = document.createTextNode('New Content...');
    p.appendChild(text);
    document.getElementById('test').appendChild(p);
}
//--></script>
</head>
<body onload="a()">

<p id="test">Original Content...</p>

</body>
</html>


You can learn a bit of this by searching Google for "Javascript DOM reference"...

Here is a site I found: http://www.howtocreate.co.uk/tutorials/index.php?tut=0&part=25

Hope that helps!
Summer
But I cant edit the <body> part , I want the codes in <head> that can insert codes into </body> . How ?

Anyway , thx for making the codes .
kv
in your javascript,

Code:

document.clear()


will erase the entire document. Then you can write whatever you want with

Code:

document.write()
LukeakaDanish
You might wanna take a look at node manipulation (the stuff SystemWisdom was talking about)

With this you can insert html elements and text anywhere in the <body> section of your page from a javascript somewhere else in the document (eg. the head:D)

I would recomend catching some tutorial with google but my page (majorly under construction) is a decent example, where the linkmenu creates itself as the page is loaded:

lukedk.frih.net/

If you view the source you will notice the lack of menu in the body section.

I have made a few empty divs which javascript then fills out onload using "parent.appendChild(newchild);"

Hope this helps you
Related topics
Force Javascript to write into <body> ??
Can't I put javascript in PHP echo <<< ?
<input> MUST be in <form>?
Automatic download start !!
Styling <abbr> in IE
Tutorial: Image Rollovers w/ Javascript
Java tutorials
Javascript help plz
General .htaccess tutorial.
Rotating advertising banner - javascript
Jquery <img> click problem.
PB PHP, Iframe and Javascript
nice background effect
Site Nav Suggestions...
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.