Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Help - .js File !

  1. #1
    Join Date
    Jan 2007
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help - .js File !

    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 ?

  2. #2
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    remove the
    Code:
    <script></script>
    code from the script and save it as something.js where something being the name. in every page you want it in add
    Code:
    <script type="text/javascript" src="path/something.js"></script>
    or if it is in the same directory add:
    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.

  3. #3
    Join Date
    Jan 2007
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Its not working

    I put this in .js & never showing the test top of the pages
    <div>EXPLAME TExT</div>

  4. #4
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Quote Originally Posted by FunaGuy View Post
    Its not working

    I put this in .js & never showing the test top of the pages
    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.

  5. #5
    Join Date
    Jan 2007
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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.

  6. #6
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    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....

  7. #7
    Join Date
    Jan 2007
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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

  8. #8
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    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>

  9. #9
    Join Date
    Jan 2007
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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

  10. #10
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •