Tuesday, 14 May 2013

About DOM

Authour:I will teach you courses online

C Language C++ Asp.net VB.net Oracle Hardware and Networking MCSE
Contact: Name: Shrinivas Mobileno:919703619391 E-mail: vas.shrinivas002@gmail.com

About DOM


Did you read below link


http://javascriptwithshrinivas.blogspot.in/2013/05/about-objects.html


Then follow below.
The objects in the DOM have properties and methods
When u refer to an object you use the parent object name followed by
the child object name or names, separated by dot
windows.document.image9

windows is parent object for all the objects




Using Window Object


Main browser object hierarchy is windows object. This is browser window. We now that every object has certain methods and properties


Windows object also has some properties and methods


One method of window object is alert(), displays a message in an alert box.


Using Window Object

Main browser object hierarchy is windows object. This is browser window. We now that every object has certain methods and properties

Windows object also has some properties and methods

One method of window object is alert(), displays a message in an alert box.


Working with Web Documents:

so you have a doubt how Web Document look like 

See above image i have open chrome browser, In that you can find 4 tabs
1).Inbox tab
2).Blogger tab
3).Javascript tab
4).Javascript tab

above 4 are Web Documents



Inbox tab-Web Document
Blogger tab-Web Document
Javascript tab-Web Document
Javascript tab-Web Document

The document object represents a web document, or page. Web documents are displayed within browser.

You can use document.write 

OR

 window.document.write

Some of properties of Document object are

document.URL: Specifies document URL
document.title: Title of the current page
document.lastModified:Is the date when document last modified
document.bgColor:Back ground color of the document(text)
document.fgColor:Foreground color of the document(text)
document.linkColor, document.alinkColor:These are colors of the links
document.cookie: Enable us to read or set  a cookie for the particular documents.

document.lastModified: is the date the document was last modified, Comes from server.

copy and paste below code and test it in internet explorer


<html>

<head>

<title>Testing Document </title>
</head>

<body>
<p> This page was last modified on 

<script type="text/javascript">

document.write(document.lastModified);

</script>

</p>

</body>


</html>

Writing text in a Document: Programmers now how to show output to LCD screen, But as a web developer you want to show output were??????

to Documents but how???

through one method that is document.write

above method print text as part of HTML document window. This statement is used whenever you need to include output in a web page.

You write something to document. Now you want to go next line use BR

"</BR>" is for next line.


Use below code




<html>

<head>
<title> your home page </title>
</head>


<body>

<h1>Welcome to our blog</h1>


<p>





<script type="text/javascript">

document.write("abc" + "<BR>"); 
document.write("text");




</script>
</p>

</body>



</html>


explanation about above code

document is object
write is method
"abc" is text
+ is for concatenation
"<BR>" is for next line

document.write("abc" + "<BR>") 
line1:abc
line 2:text

Actually what happens

first because of document.write      we can see abc on line1:abc 

Next

Because of "<BR>"    cursor will go to next line that is line 2

line 2:text


that's it.

Accessing Browser History:

Why I wrote history hear, History all ways deals with past. What have been visited before or after the current one?

You now that every object has certain methods and properties

History object has one property called length

This length property contains number of different locations that the user visited.

History obect has three methods you can use to move through the history list:


history.go() - If u use this function it's not necessary press back button again and again. For example, history.go(-2) is equivalent to pressing the Back button twice u can assign history.go(-3) or history.go(-4) depends on u r requirement.

history.back()-Go to the previous URL in history list.

history.forward ()-Loads the next URL in the history list. Might be someone don't understand what is forward, it’s simple in tapes or some music devices you can found forward options (I think now you understand). Let us assume you have 5 songs by clicking forward option you can jump to next song.

Like that while browsing you went some were by clicking back button(1 page). Now you want to go 5th page, by clicking forward you can go to 5th page.

Next most important topic is LOCATION  OBJECT

A third child of the windows object is the location object. This object stores information abt the current URL stored in window.


Suppose if I execute below command a URL will displayed in the current window.

window.Location.href="http://www.amcda909.com";

Above command href is property; it contains entire URL of current windows location.

If i want certain portion of URL i can use various properties of LOCATION object.


to explain these properties, Observe following URL:



location.pathname is the filename part of the URL(test.cgi)

location.search is the query portion of the URL

location.hash is the anchor name used in the URL, Anchors will explained later.

Another two methods of  location object:

location.reload(): This is same as reload button on toolbar.

location.replace():Replaces current location with a new one. This is similar to setting the location object's properties our self.











No comments:

Post a Comment