I added .js javascript file to my site all pages and i want to show text msg above all pages thought .js...so how can i add message in .js to show on all pages ?
I added .js javascript file to my site all pages and i want to show text msg above all pages thought .js...so how can i add message in .js to show on all pages ?
remove thecode from the script and save it as something.js where something being the name. in every page you want it in addCode:<script></script>or if it is in the same directory add:Code:<script type="text/javascript" src="path/something.js"></script>Code:<script type="text/javascript" src="something.js"></script>
[Jasme Library (Javascript Motion Effects)] My Site
/\/\@§†ê® §©®¡þ† /\/\@|{ê®
There are 10 kinds of people in the world, those that understand binary and those that don't.
Its not working
I put this in .js & never showing the test top of the pages
<div>EXPLAME TExT</div>
If you want to show some message in your pages you need to do the following things:
1. You need to provide some container/placeholder where the value can be displayed (divs, spans, inputs, etc).
2. You can create a new element in the document and display the message in it using the DOM based methods.
3. Each page will have a container/placeholder in which the message is preloaded but the placeholder/container is hidden using the JavaScript we show/hide the container based on your requirement.
If you directly place any HTML tags inside your JS file it is not going to bbe displayed as you've expected.
i really dont know how to do that
can u please make it for me...i really need it bcz i cant edit the whole pages of my website to add text (e.g update, news, note .etc) so please if u can make it in .js its really nice for me.
1. You can place the first section within your <script> tags:
window.onload = function(){
document.getElementById('mesg_container').style.display = 'block';
}
2. Place the below mentioned item in each of your page where you need to show the message. Within <body> tags. You can have a CSS style which is needed for your purpose.
<div id="mesg_container" style="display:none;">Your message goes here</div>
The idea is the HTML file will have a mesg_container element where you stored the message and initially it will be hidden and when the page loads the container will be shown.
I don't know why you would like to show the message using JavaScript....
I have unlimited pages and its very hard to add that <div> in each pages...thats y i am asking for javascript .js...bcz .js file link already added in all pages i dont need to edit each pages everything just put the msg in .js file and msg suld be show
Check the following code in which the JS code inserts a DIV element which contains the message in between two already existing elements:
Code:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Dynamic Element Insertion</title> <style type="text/css"> #mesg_container { width: 120px; padding: 2px; background-color: #e5eef9; color:#000; border:1px solid red; } </style> <script type="text/javascript"> function initMsgElemInsert(){ var bdy = document.body; var newEl = newElem('div','message goes here'); bdy.insertBefore(newEl,document.getElementById('sec')); } function newElem(tag,value){ var newEl = document.createElement(tag); newEl.appendChild(document.createTextNode(value)) newEl .id = 'mesg_container'; return newEl; } window.onload = function(){ //setTimeout('initMsgElemInsert()',1000); initMsgElemInsert(); } </script> </head> <body> <div id="first">First Div</div> <div id="sec">Second Div</div> </body> </html>
bro, i think u misunderstood...i want this every thing in .js file not in html...i dont want to touch html pages...whenever i want to change the message just open .js file and change the msg text and upload on web...thats it
First of all where exactly you want to show your message? You didn't mention the position so it is difficult to tell you how you can place your message in your pages.
Secondly if you check my JS function it demonstrates how you can insert an HTML element without touching HTML pages if you know the structure of your pages you can modify the JS code in a manner that fits for your purpose.
My code was just to demonstrate how the elements is being inserted dynamically using JS code.
Bookmarks