Your SlideShare is downloading. ×
12 Javascript(lect 4) php
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

12 Javascript(lect 4) php

71
views

Published on

Published in: Education, Technology

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
71
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org Hidaya Institute of Science & Technology www.histpk.org A Division of Hidaya Trust, Pakistan
  • 2. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org JAVASCRIPT BY: MUHAMMAD BAQAR QAZI
  • 3. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org HISTORY AND LOCATION OBJECT •Each browser window or frame maintains a bunch of other information about the page you are currently visiting and where you have been. •The URL of the page you see in the window is called the location, and browsers store this information in the location object. •As you surf the Web, the browser stores the URLs of your past pages in the history object. •You can manually view what that object contains by looking in the browser menu for the item that enables you to jump back to a previously visited page.
  • 4. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org HISTORY •As a user surfs the web, the browser maintains a list of URLs for the most recent stops. •This list is represented in the scriptable object model by the history object. [window.]history.property | method ([parameters]) length: The length property of the history object returns the number of elements in the history list. history.length
  • 5. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org HISTORY back(): •The back() method of the history object takes the user to the previous page. The functionality results in the same as pressing the back button of the browser. history.back() forward(): •The forward() method of the history object loads the next URL in the History list. The functionality results are the same as pressing the forward button of the browser. history.forward() go(): If the programmer wishes to load a specified URL from the History list, then the go method of history object can be used. history.go(number) number can be positive or negative
  • 6. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org LOCATION OBJECT •Location contains information about the current URL of the browser. The most common usage of Location is simply to use it to automatically navigate the user to another page: window.location.property|method(); href: If a programmer wants to set or return the entire URL, then the href property of location object can be used. window.location.href="http://www.google.com";
  • 7. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org LOCATION OBJECT •assign(url): Load the document at the provided URL. •replace(url): Replace the current document with the one at the provided URL. •The difference from the assign() method is that after using replace() the current page will not be saved in session history, meaning the user won't be able to use the Back button to navigate to it. •It is better to use window.location or window.location.href because calling a function can be slightly slower than accessing the property but in terms of memory there should not be a big difference.
  • 8. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org MATH OBJECT •JavaScript Math object is used to perform mathematical tasks. But unlike the String and the Date object which requires defining the object, Math object need not be defined.  •Also, it provides a few constants such as pi. • The easiest way to get a value is to define a variable and set its value to a property or function of the Math Object. •If you want to use a property, which returns a constant value (such as pi), you would write something like this: •var my_car=Math.property; •var my_pie=Math.PI; •This returns the pi constant, a number with lots of decimals, or 3.14..... •If you want to use a member function, which performs a calculation, you would write something like this: •var my_house=Math.function(x);
  • 9. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org MATH OBJECT Below is a table of some of the commonly used member functions of the Math object. These functions calculate values based on the parameters you send to them (except the random function): Method Function What it Does abs(x) Returns the absolute value of the variable x. cos(x) Returns the cosine of the variable x. log(x) Returns the natural log of the variable x. max(x,z) Returns the larger of the two variables x and z. min(x,z) Returns the smaller of the two variables x and z. pow(x,z) Returns the value of the variable x to the zth power. random() Returns a random number between 0 and 1. round(x) Returns the variable x rounded to the nearest integer. sin(x) Returns the sine of the variable x. sqrt(x) Returns the square root of the variable x. tan(x) ceil floor Returns the tangent of the variable x. Rounds a number UPWARDS to the nearest integer. Rounds a number DOWNWARDS to the nearest integer.
  • 10. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org MATH.RANDOM() •The random() method function of the Math object allows you to get random numbers for various uses in your scripts. You can make a random quote generator or have another type of random script. •By default, the random function returns a random number between zero and 1. This by itself isn't very useful. number in is a long random number after the decimal point. •If you want a number between zero and 4 (5 random numbers), multiply the result of the Math.random() function by 5: •var ran_number= Math.random()*5; •Now, the numbers you get will be between zero and 4- but they still will not be integers. •We need these to be integers so we can have just the five random numbers between zero and 4. •To clean up those decimals and get just the integers, we use the Math.floor() function (which removes anything after the decimal and leaves the integer portion of the number) for the result. •var ran_number= Math.floor (Math.random()*5);

×