Javascript in Hindi




Javascript in Hindi Introduction

JavaScript एक Programming Language है. JavaScript का उपयोग वेबसाइट को Develop करने के लिये किया जाता है. JavaScript को Sun Micro Systems ने Develop किया था. पहले इसका नाम LiveScript रखा गया था. जिसे बाद मे Change करके JavaScript किया गया था. JavaScript मे Object Oriented Programming Capabilities होती है. इसे HTML File के Head Dection मे Define किया जाता है.

JavaScript एक Client Side Scripting Language है. JavaScript को Client Side Scripting Language इसलिये कहा जाता है क्यूंकि JavaScript का कोड हमेशा उपयोगकर्ता के ब्राउज़र पर Execute होता है.

इसका अधिकतर उपयोग Game और Mobile Application Development के लिये किया जाता है. JavaScript का फायदा यह है कि ये सभी Web Browsers को समर्थन करती है.

For Example

<!DOCTYPE html>
<html>
   <head>
      <title>Javascript First Example</title>
   </head>	
   <body>
      <h2>Javascript First Example</h2>

      <p id="demo">You are now learning Tutorialsroot</p>

      <button type="button" onclick='document.getElementById("demo").innerHTML
        = "Hello Tutorialsroot!"'>Click Me!</button>
		
   </body>
</html>

Output

JavaScript मे बहुत से keyword का उपयोग किया गया है जिनकी सूची आप नीचे Table मे देख सकते है.

Keywords
var function if
else do while
for switch break
continue return try
catch finally debugger
case class this
default false true
in instanceOf typeOf
new null throw
void width delete

Features of JavaScript

  • JavaScript के जरिये हम Dynamic Web Page Create कर सकते है इसके माध्यम हम Dynamically Web Page के Content को Update कर सकते है.

  • JavaScript के जरिये हम Web Page को Interactive Look दे सकते है.

  • JavaScript का Execution बहुत तेज होता है क्यूंकि यह Client Side पर Execute करता है.

  • JavaScript के जरिये हम उपयोगकर्ता को Web Page पर Logical या Mathematical Operations Perform करने की Facility Provide करा सकते है.

  • JavaScript का ज्यादातर उपयोग Form Validation मे किया जाता है क्यूंकि JavaScript का Interaction Server से बहुत कम होता है.

Javascript in Hindi Data Types

JavaScript Variables मे बहुत से Data Types को Catch कर सकते है जैसे Numbers, Strings, Objects आदि. कई ऐसी Programming Language है जिसमे जिस Type का Value आप Variable मे Store कराना चाहते है उसी Data Type का Variable भी Declare होना चाहिए.

उदाहरण के लिए C Programming Language मे यदि आप Variable मे कोई Number Store कराना चाहते है तो आपको Variable का Data Type Int Declare करना होगा आप एक Number को Store कराने के लिए Char Data Type का Variable उपयोग नहीं कर सकते.

लेकिन JavaScript मे ऐसा नहीं है JavaScript मे आप Same Variable मे हर तरह के Data Type की Value को Store करा सकते है.

JavaScript मे दो प्रकार के Data Types होते है.

  • Primitive Data Type

  • Non-primitive (reference) Data Type

Primitive Data Type

Javascript मे पांच के प्रकार Primitive Data Type होते है जैसे String, Number, Boolean or Null or Undefined. एक String "New", "hello" आदि जैसे Character Sequence को Represent करने के लिए प्रयोग किया जाता है संख्या उदाहरण के लिए कोई भी Value हो सकती है - 10,20,30,40 आदि.

Boolean Data Type का उपयोग किसी भी वास्तविक या गलत Representation के लिए किया जा सकता है. Undefined Data Type मे कोई भी अनिर्धारित Value हो सकती है. और Null एक Value को Represents करता है.

Data Type Description
String String Characters के Sequence को Represents करता है जैसे "New", "hello".
Number Number Numeric Values को Represents करता है जैसे 200.
Boolean Boolean Values को Represents करता है की यह Values False हे या True.
Undefined यह Undefined Values को Represents करता है.
Null Null Values को Represents करता है और यह Check करता है की कोई भी Value नही है.

For Example

<!DOCTYPE html>
<html>
   <head>
      <title>Primitive Data Type Example</title>
   </head>	
   <body>
      <h2>Primitive Data Type Example</h2>
      <p id="demo"></p>
      <script type="text/javascript">
         document.getElementById("demo").innerHTML = 
         typeof "john" + "<br>" + 
         typeof 3.14 + "<br>" +
         typeof true + "<br>" +
         typeof false;
      </script>
   </body>
</html>

Output

Non-primitive Data Type

Non-primitive Data Type Object, Array और RegExp भी हो सकते है. Object एक Instance को Represents करता है है जिसके माध्यम से हम Numbers का उपयोग कर सकते है.

Array समान प्रकार की Values को Represents करने के लिए उपयोग किया जाता है. जबकि RegExp एक Regular Expression को Represents करता है.

Data Type Description
Object Object एक Instance को Represents करता है जिसके माध्यम से हम Numbers का उपयोग कर सकते है.
RegExp RegExp एक Regular Expression को Represents करता है.
Array Array समान Values के Group को Represents करता है.

For Example

<!DOCTYPE html>
<html>
   <head>
      <title>Non-primitive Data Type Example</title>
   </head>	
   <body>
      <h2>Non-primitive Data Type Example</h2>
      <p id="demo"></p>
      <script type="text/javascript">
         var myVar = 100;
         myVar = true;
         myVar = null;
         myVar = undefined;
         myVar = "Steve";
         alert(myVar); 
      </script>
   </body>
</html>

Output

Javascript in Hindi Variable

JavaScript मे Variables Create करना सामान्य Languages से अलग होता है. JavaScript मे Variables Create करने के लिए आपको Data Type को परिभाषित करने की जरुरत नही होती है. आप जो Value Variable मे डालते है तो उस Value के आधार पर JavaScript Variable का Data Type Automatically निर्णय कर लेती है. JavaScript मे Variables Create करना बहुत आसान माना जाता है. इससे पहले की आप Variables Create करे आइये JavaScript मे Variables Create करने के कुछ Rules के बारे मे जान लेते है.

JavaScript मे Variables Create करना बहुत ही आसान है. इसके लिए आप var keyword उपयोग करते है. JavaScript मे Variables Create करने का structure नीचे दिया जा रहा है.


var varName = value;


Rules for Creating Variables

  • आपके Variable का नाम किसी Letter, Underscore या $ sign से शुरू होना चाहिए.

  • आप Variables के नाम मे Numbers (1,2,3,4,5,6,7,8,9) भी उपयोग कर सकते है.

  • JavaScript Variables Case Sensitive होते है.

Types of Variables in JavaScript

JavaScript मे Variable दो प्रकार के होते है Local Variable और Global Variable . इनको Scope के According Categories किया गया है इनके बारे मे नीचे दिया जा रहा है जिनको आप विस्तार से जान सकते है.

JavaScript Local Variable

Local Variables वो Variables होते है जिनका Scope किसी Function तक Limited रहता है. ऐसे Variables किसी Function के अंदर Create किये जाते है और वे उस Function मे ही काम करते है. Function के बाहर आप इन Variables को उपयोग नही कर सकते है. जिस Block या Function मे ये Variable Create किये जाते है ये सिर्फ उसी मे काम करते है ये उनका Scope कहलाता है. यदि आप Local Variables को उनके Scope के बाहर Access करने की कोशिश करते है तो Undefined Variable Error Generate होती है

<!DOCTYPE html>
<html>
   <head>
      <title>Local variable Example</title>
   </head>	
   <body>
      <h2>Local variable Example</h2>
      <script>
         var myVar = "local";  // Declare a local variable
         document.write(myVar);
      </script>
   </body>
</html>

Output

JavaScript Global Variable

Global Variable एक Global Scope होता है इसको आप Javascript Code मे कही पर भी परिभाषित कर सकते हो. इस तरह के Variables का Scope पुरे प्रोग्राम मे होता है.

<!DOCTYPE html>
<html>
   <head>
      <title>Global variable Example</title>
   </head>	
   <body>
      <h2>Global variable Example</h2>
      <script>
         var data=400;//gloabal variable  
         function a(){  
            document.writeln(data);  
         }  
         function b(){  
            document.writeln(data);  
         }  
         a();//calling JavaScript function
         b();
      </script>
   </body>
</html>

Output

Javascript in Hindi Operators

JavaScript मे Operators का उपयोग किसी भी Value और Variable की गणना करने के लिए किया जाता है. JavaScript मे Operators Operation के समान होते है जो अन्य Programming Languages मे दिखाई देते है. और ये सब से अधिक Addition, Subtraction आदि मे होते है.

Operators जिन Variables पर Apply होते है या जिन Variables के साथ उपयोग किये जाते है उन Variables को Operands कहा जाता है. जैसे कि -


c = a+b;


इस Statement मे a और b Operands है. C भी एक Operand है क्योंकि (=) Operator इस पर Apply हो रहा है.

Types of Operators

Operators Unary और Binary दो तरह के होते है. Unary Operators वो Operators होते है जो सिर्फ एक Variable पर ही Apply होते है. जैसे की (~) NOT Operator है ये Operator सिर्फ एक ही Variable के साथ Apply किया जाता है.

Binary Operators वो Operators होते है जिनके Execution के लिए दो Operators Required होते है. जैसे की (+) Operator है. इस Operator को आप किसी Single Variable के साथ उपयोग नही कर सकते है. इस Variable को Execute होने के लिए दो Operands की आवश्यकता होती है.

JavaScript मे Operators को कई भागो मे बाँटा गया है -

  • Arithmetic Operators

  • Comparison (Relational) Operators

  • Bitwise Operators

  • Logical Operators

  • Assignment Operators

Arithmetic Operators

Arithmetic Operators एक Value या Variable के रूप मे Single Value को वापस कर देते है.

OperatorDescriptionExample
+ Addition 2 + 4
- Subtraction 6 - 2
* Multiplication 5 * 3
/ Division15 / 3
% Modulus43 % 10

For Example

<!DOCTYPE html>
<html>
   <head>
      <title>JavaScript Arithmetic Operators</title>
   </head>
   <body>
      <script type="text/javascript">
         <!--
            var a = 43;
            var b = 20;
            var c = "Test";
            var linebreak = "<br />";
         
            document.write("a + b = ");
            result = a + b;
            document.write(result);
            document.write(linebreak);
         
            document.write("a - b = ");
            result = a - b;
            document.write(result);
            document.write(linebreak);
         
            document.write("a / b = ");
            result = a / b;
            document.write(result);
            document.write(linebreak);
         
            document.write("a % b = ");
            result = a % b;
            document.write(result);
            document.write(linebreak);
         
            document.write("a + b + c = ");
            result = a + b + c;
            document.write(result);
            document.write(linebreak);
         
            a = ++a;
            document.write("++a = ");
            result = ++a;
            document.write(result);
            document.write(linebreak);
         
            b = --b;
            document.write("--b = ");
            result = --b;
            document.write(result);
            document.write(linebreak);
         //-->
      </script>
   </body>
</html>								

Output

Comparison (Relational) Operators

Relational Operators के द्वारा आप दो Variables की Values को Compare कर सकते है. यह Operators ज्यादातर Control Statements मे उपयोग होते है जब आप Logic Build करने की कोशिश करते है. जैसे की कौन सा Variable बड़ा या छोटा है.

OperatorDescriptionExampleResult
== Equal Tox == yfalse
!= Not Equal Tox != ytrue
< Less Thanx < y true
>Greater Thanx > y false
<= Less Than or Equal Tox <= y true
>= Greater Than or Equal Tox >= y false

For Example

<!DOCTYPE html>
<html>
   <head>
      <title>JavaScript Comparison Operators</title>
   </head>
   <body>
      <script type="text/javascript">
         <!--
            var a = 20;
            var b = 30;
            var linebreak = "<br />";
      
            document.write("(a == b) => ");
            result = (a == b);
            document.write(result);
            document.write(linebreak);
         
            document.write("(a < b) => ");
            result = (a < b);
            document.write(result);
            document.write(linebreak);
         
            document.write("(a > b) => ");
            result = (a > b);
            document.write(result);
            document.write(linebreak);
         
            document.write("(a != b) => ");
            result = (a != b);
            document.write(result);
            document.write(linebreak);
         
            document.write("(a >= b) => ");
            result = (a >= b);
            document.write(result);
            document.write(linebreak);
         
            document.write("(a <= b) => ");
            result = (a <= b);
            document.write(result);
            document.write(linebreak);
         //-->
      </script>
   </body>
</html>   								

Output

Bitwise Operators

सभी Variables की Values Bits मे Convert होती है. Bit Wise Operator के द्वारा आप Bits पर Operations Perform कर सकते है. यह Operators भी Control Statements मे उपयोग किये जाते है.

OperatorDescriptionExample
&Bitwise AND(10==20 & 20==33) = false
|Bitwise OR(10==20 | 20==33) = false
^Bitwise XOR(10==20 ^ 20==33) = false
~Bitwise NOT (~10) = -10
<<Bitwise Left Shift(10<<2) = 40
>>Bitwise Right Shift(10>>2) = 2
>>>Bitwise Right Shift with Zero(10>>>2) = 2

For Example

<!DOCTYPE html>
<html>
   <head>
      <title>JavaScript Bitwise Operators</title>
   </head>
  <body>
      <script type="text/javascript">
         <!--
            var a = 3; // Bit presentation 11
            var b = 3; // Bit presentation 12
            var linebreak = "<br />";
         
            document.write("(a & b) => ");
            result = (a & b);
            document.write(result);
            document.write(linebreak);
         
            document.write("(a | b) => ");
            result = (a | b);
            document.write(result);
            document.write(linebreak);
         
            document.write("(a ^ b) => ");
            result = (a ^ b);
            document.write(result);
            document.write(linebreak);
         
            document.write("(~b) => ");
            result = (~b);
            document.write(result);
            document.write(linebreak);
         
            document.write("(a << b) => ");
            result = (a << b);
            document.write(result);
            document.write(linebreak);
         
            document.write("(a >> b) => ");
            result = (a >> b);
            document.write(result);
            document.write(linebreak);
         //-->
      </script>
   </body>
</html>   								

Output

Logical Operators

Logical Operators का उपयोग दो या अधिक Conditions को Combine करने के लिये किया जाता है.

Operator Example Description
Logical AND ( && ) a  && b is true if both a and b are true.
Logical OR ( || ) a || b is true if either a or b is true.
Logical NOT ( ! ) !a is true if a is not true.

For Example

<!DOCTYPE html>
<html>
   <head>
      <title>JavaScript Logical Operators</title>
   </head>
   <body>
      <script type="text/javascript">
         <!--
            var a = true;
            var b = false;
            var linebreak = "<br />";
      
            document.write("(a && b) => ");
            result = (a && b);
            document.write(result);
            document.write(linebreak);
         
            document.write("(a || b) => ");
            result = (a || b);
            document.write(result);
            document.write(linebreak);
         
            document.write("!(a && b) => ");
            result = (!(a && b));
            document.write(result);
            document.write(linebreak);
         //-->
      </script>
   </body>
</html>   								

Output

Assignment Operators

Assignment Operators का उपयोग Left Operand Value को Right Operand Value के बराबर करने के लिये किया जाता है.

OperatorDescriptionExample
=Assign10+10 = 20
+=Add and assignvar a=10; a+=20; Now a = 30
-=Subtract and assignvar a=20; a-=10; Now a = 10
*=Multiply and assignvar a=10; a*=20; Now a = 200
/=Divide and assignvar a=10; a/=2; Now a = 5
%=Modulus and assignvar a=10; a%=2; Now a = 0

For Example

<!DOCTYPE html>
<html>
   <head>
      <title>JavaScript Assignment Operators</title>
   </head>
  <body>
      <script type="text/javascript">
         <!--
            var a = 43;
            var b = 20;
            var linebreak = "<br />";
         
            document.write("Value of a => (a = b) => ");
            result = (a = b);
            document.write(result);
            document.write(linebreak);
         
            document.write("Value of a => (a += b) => ");
            result = (a += b);
            document.write(result);
            document.write(linebreak);
         
            document.write("Value of a => (a -= b) => ");
            result = (a -= b);
            document.write(result);
            document.write(linebreak);
         
            document.write("Value of a => (a *= b) => ");
            result = (a *= b);
            document.write(result);
            document.write(linebreak);
         
            document.write("Value of a => (a /= b) => ");
            result = (a /= b);
            document.write(result);
            document.write(linebreak);
         
            document.write("Value of a => (a %= b) => ");
            result = (a %= b);
            document.write(result);
            document.write(linebreak);
         //-->
      </script>
   </body>
</html>   								

Output

Javascript in Hindi Loop

Javascript मे Loop बहुत उपयोगी होता है. Loop का प्रयोग हम Code को उसी Line मे बार बार Execute करने के लिए करते है और तब तक Code को Execute करते हैं जब तक कोई एक Condition True हो.

मान ले कि यदि आप अपने Web Page मे Hii MSG को 10 बार Type करना चाहते है तो आप उसको उसी Line को 10 बार Type कर सकते है. लेकिन अगर आप Loop का उपयोग करते है तो आप केवल 2, 3 Line मे पूर्ण हो सकते हैं .

Type of Loop

Loop Four प्रकार के होते है.

  • The For Loop

  • The While Loop

  • The Do while Loop

  • The For in Loop

The For Loop

JavaScript Program मे कोई ऐसा Statement है या Block of Statements है जिसे आप Multiple Times Execute कराना चाहते है तो इस Situation मे आप For Loop का उपयोग कर सकते है. For Loop मे तीन Expressions उपयोग किये जाते है Initialization Expression, Condition Expression और Update Expression.

Syntax

<script>
   for(initialize ; test ; increment/decrement)
   {
      statement(s);
   }
</script>

For Example

<!DOCTYPE html>
<html>
   <head>
     <title>JavaScript For Loop Example</title>
   </head>
   <body>
      <script type="text/javascript"> 
         for (i=1; i<=10; i++)  
         {  
            document.write(i + "<br/>")  
         }  
      </script>  
   </body>
</html>   								

Output

The While Loop

While Loop मे सबसे पहले Condition Check की जाती है अगर Condition True हो तभी While Loop के Inside Statements को Execute किया जाता है. While Loop के Inside Statements को Execute करने के बाद दोबारा से Condition को Check की जाती है अगर इस बार भी Condition True होती है तो फिर से While Loop के Inside Statements को Execute किया जाता है और यह Process तब तक चलता रहता है जब तक की Condition False ना हो जाये. Condition के False होते ही Loop को Terminate कर दिया जाता है.

अगर Condition पहली बार में ही False हो जाये तब While Loop के Inside Statements को बिना Execute किये ही While Loop को Terminate कर दिया जाता है.

Syntax

<script>
   while (condition)  
   {  
     code to be executed  
   }  
</script>

For Example

<!DOCTYPE html>
<html>
   <head>
      <title>JavaScript While Loop Example</title>
   </head>
   <body>
      <script type="text/javascript"> 
         var i=10;  
         while (i<=20)  
            {  
               document.write(i + "<br/>");  
               i++;  
            }  
      </script>  
   </body>
</html>   								

Output

The Do while Loop

JavaScript Program मे कई ऐसे Statement या Block of Statements होते है जिसे आप Multiple Times Execute कराना चाहते है तो इस Situation मे आप do..while Loop का उपयोग कर सकते है.

Do while Loop एक Block of Code को बार बार तब तक Execute करता रहता है जब तक की Do while Loop मे दी गई Condition True रहती है Condition के False होते ही Loop को Terminate कर दिया जाता है.

Syntax

<script>
   do
   {
      block of code to be executed
   }  
</script>

For Example

<!DOCTYPE html>
<html>
   <head>
      <title>JavaScript Do While Loop Example</title>
   </head>
   <body>
      <script type="text/javascript">
         document.write("<b>Using do...while loops </b><br />");
         var i = 2;
         document.write("Even numbers less than 20<br />");
         do
         {
            document.write(i + "<br />");

            i = i + 2;

         }
         while(i<20)
      </script>  
   </body>
</html>   								

Output

The For in Loop

For in Loop का उपयोग Array और Object के साथ काम करने के लिये किया जाता है.

Syntax

<script>
   for(index in arrayName)
   {
      // Code Block
   }
</script>

For Example

<!DOCTYPE html>
<html>
   <head>
      <title>JavaScript Do For in Loop Example</title>
   </head>
   <body>
      <script type="text/javascript">
         function demo(){
            var phone = new Array(5);
            phone[0] = "Apple";
            phone[1] = "Samsung";
            phone[2] = "Sony";
            phone[3] = "Xolo";
            phone[4] = "Nokia";      
            phone[5] = "Apple6";      
            phone[6] = "Apple7";      
            phone[7] = "Apple8";      
            for (var i in phone)
            {
               document.write("phone[" + i + "]  = " + phone[i] + "<br/>");        
            } 

         }
      </script>  
      <p>Click the button below</p>
      <button onclick="demo()">loop: For in</button>
   </body>
</html>   								

Output

Javascript in Hindi Function

Function एक Line of Code का नाम होता है इसको हम Block of Code भी कहते है. Javascript मे Function एक विशेष कार्य को करने के लिए Sesign किया गया Code का एक Block है. Javascript या किसी भी Programming Language मे Function एक Relatively Code होता है जिस को आप अपने Programs मे कहीं पर भी Call करा सकते है.

एक Function किसी भी Program की Value को प्राप्त कर सकता है और Return कर सकता है और इस तरह आप हर बार एक ही Code लिखने और एक Modular Structured Program बनाने की प्रक्रिया को नज़र अंदाज़ कर सकते है.

Javascript Function की सहायता से आप अपने Program को कई कार्यों मे प्राप्त कर सकते है और Function की सहायता से आप अपने Program को बहुत आसानी से Managed कर सकते है. Javascript मे Function Define करना बहुत आसान होता है Javascript मे Function को Define करने के लिए आप Function Keyword का उपयोग करते है.

JavaScript Function Syntax

<script>
   function functionName([arg1, arg2, ...argN]){  
      //code to be executed 
   }
</script>

For Example

<!DOCTYPE html>
<html>
   <head>
      <title>JavaScript Function Example</title>
   </head>
   <body>
      <script type="text/javascript">
         function getname()
         {
            name=prompt("Enter Your Name");
            alert("Welcome Mr/Mrs " + name);
         }
      </script>  
      <form>
         <input type="button" value="Click" onclick="getname()"/>
      </form>
   </body>
</html>   								

Output

JavaScript Function Arguments

Function Arguments मे हम Arguments को पास करके Function को Call कर सकते है.

<!DOCTYPE html>
<html>
<head>
   <meta charset="UTF-8">
   <title>JavaScript Function Arguments Example</title>
</head>
<body>
   <script type="text/javascript">
	
      function getname(number){  
         alert(number*number*number);  
      }  
		
   </script>  
	
   <form>
      <input type="button" value="Click" onclick="getname(4)"/>
   </form>

</body>
</html>   								

Output

Function with Return Value

जब हम Function को Call करते है तो Function हमको एक Value वापस करता है जिसको हम अपने Program मे उपयोग करते है.

<!DOCTYPE html>
<html>
<head>
   <meta charset="UTF-8">
   <title>JavaScript Function with Return Value Example</title>
</head>
<body>
   <script type="text/javascript">
	
      function concatenate(first, last)
         {
            var full;
            full = first + last;
            return full;
         }
         
         function secondFunction()
         {
            var result;
            result = concatenate('Amreen', 'Begum');
            document.write (result );
         }
		
   </script>  
	
   <p>Click the following button to call the function</p>

   <form>
      <input type="button" onclick="secondFunction()" value="Call Function">
   </form>


</body>
</html>   								

Output

Javascript in Hindi Object

Javascript Object उन Properties का एक Collection है जहां हर Properties का एक Name और एक Value होती है जो Hash, Map या अन्य Languages मे Dictionary के समान होता है. एक String का Name कोई भी String हो सकता है जिसमे खाली String भी शामिल होते है. Value कोई भी अन्य Value हो सकती है जैसे String, Boolean, Number, Null, लेकिन यह Undefined नही हो सकती.

Object का उपयोग शुरू करने के बाद भी Object की Properties को Define किया जा सकता है. लेकिन सबसे पहले आइए देखें कि हम Javascript मे Object को कैसे बनाते है.

एक नया Object को बनाने का सबसे आसान तरीका Object Literal Notation के साथ होता है जो कि Curly Braces: {} की एक जोड़ी से Bracketed किया जाता है.

Creating Objects in JavaScript

JavaScript Objects को बनाने के तीन तरीके प्रदान करता है.

  • Object Literal

  • Creating Instance of Object Directly

  • Using an Object Constructor

Object Literal

Object Literal Notation मूल रूप से key का एक Array है. Value Pairs एक Colon के साथ Keys और Values को अलग करते है और प्रत्येक Key के बाद एक Comma key:value को जोड़ते है और यह केवल एक नियमित Array की तरह अंतिम के अलावा होता है.

For Example

<!DOCTYPE html>
<html>
   <head>
      <title>Javascript Object Literal Example</title>
   </head>
   <body>	
      <script type="text/javascript">
         emp={id:202,name:"Amreen Begum",salary:60000}  
         document.write(emp.id+" "+emp.name+" "+emp.salary);
      </script>
   </body>
</html>

Output

Creating Instance of Object Directly

किसी Object का एक नया Instance को बनाने के लिए हम New Keyword का उपयोग करते है. यह Keyword एक Object का एक नया Instance को बनाता है जिससे हम फिर एक Variable को Assign कर सकते है.

For Example

<!DOCTYPE html>
<html>
   <head>
      <title>Creating Instance of Object Directly Example</title>
   </head>
   <body>	
      <script type="text/javascript">
         var emp=new Object();  
         emp.id=301;  
         emp.name="Nausheen Khan";  
         emp.salary=70000;  
         document.write(emp.id+" "+emp.name+" "+emp.salary);
      </script>
   </body>
</html>

Output

Using an Object Constructor

यहा पर आपको Argument के साथ Function को बनाने की आवश्यकता होती है प्रत्येक Argument Value को इस Object का उपयोग करके वर्तमान Object में Assigned किया जा सकता है. और यह Keyword मौजूदा Object को दर्शाता है.

For Example

<!DOCTYPE html>
<html>
   <head>
      <title>Using an Object Constructor Example</title>
   </head>
   <body>	
      <script type="text/javascript">
         function emp(id,name,salary){  
            this.id=id;  
            this.name=name;  
            this.salary=salary;  
         }  
         e=new emp(203,"Amreen Begum",10000);  
         document.write(e.id+" "+e.name+" "+e.salary);
      </script>
   </body>
</html>

Output

Javascript in Hindi String

JavaScript मे Strings का उपयोग Text को Store और Manipulat करने के लिए किया जाता है. Strings Text और Value से बने होते है और इसमे Contain Letters और Numbers, Symbols भी हो होते है और यहां तक कि Emoji भी हो सकते है.

JavaScript Dynamic और Interactive Web Pages Generate करने के लिए उपयोग की जाती है. यही वजह है की JavaScript मे Strings को Objects Define किया गया है. Strings के Objects होने से आप Strings के Presentation को Page Load होते समय अपने According Control कर सकते है.

JavaScript Web Page मे String Representation को Control करने के लिए आपको कई Methods Provide करती है. आप इन Methods की मदद से आसानी से Strings पर Operations Perform कर पाते है. आप JavaScript मे Strings किसी भी Normal Variable की तरह Create करते है. इसका सामान्य Syntax निचे दिया जा रहा है.

Syntax


var stringName = "text";


Type of Strings

Javascript मे String दो प्रकार के होते है.

  • String Literal

  • String Object

String Literal

String Literal को Double Quotes का प्रयोग करके बनाया गया है.

<!DOCTYPE html>
<html>
   <head>
      <title>String Literal Example</title>
   </head>
   <body>	
	
      <script type="text/javascript">
	
         var str="This is string literal";  
         document.write(str);
			
      </script>

   </body>
</html>

Output

String Object

<!DOCTYPE html>
<html>
   <head>
      <title>String Object Example</title>
   </head>
   <body>	
	
      <script type="text/javascript">
	
         var stringname=new String("Hii javascript string object");  
         document.write(stringname);
			
      </script>

   </body>
</html>

Output

Javascript in Hindi Array

JavaScript मे Array एक Special Variable होता है. Javascript Arrays मे आप एक या एक से ज्यादा Value को एक ही समय मे Add कर सकते है.

JavaScript मे Array को एक Unit या लगातार Memory Location मे Elements के Group को Represent करने के लिए उपयोग किया जाता है. प्रत्येक Elements जो आप Array मे Enter करते हो वह Zero से Start होने वाले Unique Number के साथ Array मे Stored किया जाता है.

JavaScript मे Arrays का उपयोग एक Single Variable मे एक से अधिक Value को Store करने के लिये किया जाता है. Array एक ही प्रकार के Elements को एक Fixed Size मे Sequential के रूप मे Store करता है.

उदाहरण के लिए यदि आप कुछ समय मे किसी User की Location को Track करना चाहते है तो आप एक Array मे x और y Value को Included कर सकते है Array x और y के Examples की तुलना मे अधिक है Indexed के माध्यम से आप Data या Elements को Array मे Stored कर सकते है या और आप Elements को Array से प्राप्त कर सकते है.

Syntax


var fruits = new Array( "mango", "orange", "banana" );


For Example

<!DOCTYPE html>
<html>
   <head>
      <title>JavaScript Array Example</title>
   </head>
   <body>
      <h2>JavaScript Arrays Example</h2>
      <p id="demo"></p>	
      <script type="text/javascript">
         var fruits = ["Mango", "Banana", "Orange"];
         document.getElementById("demo").innerHTML = fruits;
      </script>
   </body>
</html>

Output

Array Properties

Arrays मे अपने built-in Variables और Functions होते है जिनको Properties और Methods के रूप मे जाना जाता है.

Property Description
Constructor

Array Function के लिए एक Context देता है जो Object से बनाया जाता है.

Index

Index मे Property String को Zero Based पर Represent करता है.

Input

Input Property केवल Matches के द्वारा बनाया गया Array है.

Length

Length Property आपके Array की Length Hold करती है.

Prototype

Prototype आपको किसी Object के Attribute और Properties को Add करने की अनुमति देता है.

Array Constructor Property

Javascript Array Constructor Property Array Function का Reference देता है जिसने Instances Prototype बनाया है.

Syntax


array.constructor


For Example

<!DOCTYPE html>
<html>
   <head>
      <title>Array constructor Property</title>
   </head>
   <body>	
      <script type="text/javascript">
	
         var arr = new Array( 10, 20, 30 );
         document.write("arr.constructor is:" + arr.constructor);
			
      </script>
   </body>
</html>

Output

Array Length Property

JavaScript आपको Array Object के साथ Length Property Provide करती है. ये Property आपके Array की Length Hold करती है. Javascript मे Array Length Property को 32-bit Integer Unsigned देता है जो Array मे Element की संख्या को Define करता है.

Syntax


array.length


For Example

<!DOCTYPE html>
<html>
   <head>
      <title>Array Length Property</title>
   </head>
   <body>	
      <script type="text/javascript">
	
         var arr = new Array( 10, 20, 30 );
         document.write("arr.length is : " + arr.length);
			
      </script>
   </body>
</html>

Output

Array Prototype Property

Prototype Property आपको किसी भी Object मे Property को जोड़ने की अनुमति देता है (Number, Boolean, String and Date).

Syntax


object.prototype.name = value


For Example

<!DOCTYPE html>
<html>
   <head>
      <title>Array Prototype Property</title>
      <script type="text/javascript">
         function book(title, author){
            this.title = title; 
            this.author  = author;
         }
      </script>
		
   </head>
   <body>	
      <script type="text/javascript">
	
         var myBook = new book("java", "Ammu");
         book.prototype.price = null;
         myBook.price = 100;
         
         document.write("Book title is : " + myBook.title + "<br>");
         document.write("Book author is : " + myBook.author + "<br>");
         document.write("Book price is : " + myBook.price + "<br>");
			
      </script>
   </body>
</html>

Output

Javascript in Hindi Cookies

Cookies के द्वारा उपयोगकर्ता की Information Store की जाती है. सामान्य रूप से जब उपयोगकर्ता किसी Website को Visit करता है तो Web Server के Pass उसकी कोई Information नहीं होती है. लेकिन Cookies के द्वारा किसी भी उपयोगकर्ता की Information Store करना संभव है.

Cookie एक Normal Text File होती है. जब भी कोई उपयोगकर्ता किसी Website को Visit करता है तो उसकी Information Cookies Text File के रूप मे Store कर ली जाती है. यह Information उपयोगकर्ता के Computer मे ही Store की जाती है. भविष्य मे जब भी उपयोगकर्ता वापस उस Website के लिए Request करता है तो उपयोगकर्ता की Request के साथ उस उपयोगकर्ता की Cookie भी Webserver को भेजी जाती है.

इस प्रकार Web Server को उस उपयोगकर्ता की Information प्राप्त हो जाती है. इस Information के आधार पर Webserver को उस उपयोगकर्ता की Preferences के बारे में पता रहता है. साथ ही इस Information के आधार पर Web Server Web Pages मे जरुरी Change भी कर सकता है.

JavaScript आपको Cookies Create करने Read करने Change करने और Delete करने की Ability Provide करती है. इसके लिए JavaScript मे document.cookie Property Available है.

JavaScript मे Cookies Create करने का सामान्य Syntax आप नीचे देख सकते है

Syntax


document.cookie = "name=value; expiry-date; path";


  • Name Value - आप जब भी Cookie मे कोई Information Store करते है तो ऐसा आप Name और Value के Pair मे करते है. उदाहरण के लिए यदि आप उपयोगकर्ता की ID Store करना चाहते है तो इसके लिए आप Id=101 को Define करेंगे.

  • Expiry Date - आप Cookies की Expiry Date भी Set कर सकते है. जो Date आप Define करेंगे उस Date के आते है की Cookie Automatically Delete हो जायेगी. Expiry Date को Expires Attribute द्वारा set किया जाता है.

  • Path - इस Parameter के द्वारा आप ये Define करते है की Cookie किस Path से Related है. यदि कोई Path नहीं दिया हुआ है तो इसका मतलब है की Cookie Current Page से Related है.

Storing Cookies

Document.cookie को Object के लिये एक String Value को नियुक्त करके सबसे आसान Cookie बना सकते है.

For Example

<!DOCTYPE html>
<html>
   <head>
      <title>Storing Cookies Example</title>
      <script type="text/javascript">
         <!--
            function WriteCookie()
            {
               if( document.myform.customer.value == "" ){
                  alert("Enter some value!");
                  return;
               }
               cookievalue= escape(document.myform.customer.value) + ";";
               document.cookie="name=" + cookievalue;
               document.write ("Setting Cookies : " + "name=" + cookievalue );
            }
         //-->
      </script>
   </head>
   <body>
   
      <form name="myform" action="">
         Enter name: <input type="text" name="customer"/>
         <input type="button" value="Set Cookie" onclick="WriteCookie();"/>
      </form>
   
   </body>
</html>

Output

Reading Cookies

JavaScript मे आप Set की गयी Cookies को आसानी से Read कर सकते है. इसके लिए आप किसी Normal Variable को document.cookie Property Assign करते है. यह Property उस Page पर Set की गयी सभी Cookies को Name और Value के Pair मे Return करती है.

For Example

<!DOCTYPE html>
<html>
   <head>
      <title>Reading Cookies Example</title>
      <script type="text/javascript">
         <!--
            function ReadCookie()
            {
               var allcookies = document.cookie;
               document.write ("All Cookies : " + allcookies );
               
               // Get all the cookies pairs in an array
               cookiearray = allcookies.split(';');
               
               // Now take key value pair out of this array
               for(var i=0; i<cookiearray.length; i++){
                 name = cookiearray[i].split('=')[0];
                 value = cookiearray[i].split('=')[1];
                 document.write ("Key is : " + name + " and Value is : "+value);
               }
            }
         //-->
      </script>
      
   </head>
   <body>
   
      <form name="myform" action="">
         <input type="button" value="Get Cookie" onclick="ReadCookie()"/>
      </form>
   
   </body>
</html>

Output

Deleting Cookies

JavaScript द्वारा किसी भी Cookie को Delete करने के लिए आप उस Cookie को दुबारा Create करते है. Cookie को दुबारा Create करते समय आप उसकी Value नही देते है. साथ ही Expires Parameter मे कोई पुरानी Date Value के रूप मे Pass करते है.

For Example

<!DOCTYPE html>
<html>
   <head>
      <title>Deleting Cookies Example</title>	
      <script type="text/javascript">
         <!--
            function WriteCookie()
            {
               var now = new Date();
               now.setMonth( now.getMonth() - 1 );
               cookievalue = escape(document.myform.customer.value) + ";"
               
               document.cookie="name=" + cookievalue;
               document.cookie = "expires=" + now.toUTCString() + ";"
               document.write("Setting Cookies : " + "name=" + cookievalue );
            }
         //-->
      </script>
      
   </head>
   <body>
   
      <form name="myform" action="">
         Enter name: <input type="text" name="customer"/>
         <input type="button" value="Set Cookie" onclick="WriteCookie()"/>
      </form>
   
   </body>
</html>

Output

Javascript in Hindi Date Object

JavaScript आपको Date और Time सम्बंधित Information Show करने के लिए Date Object Provide करती है. इस Object के साथ आपको कुछ Built in Properties और Methods Available होते है. इन Properties और Methods को उपयोग करके आप Web Page मे Date और Time से Related Operations Perform कर सकते है.

ऐसी कई स्थिति हो सकती है जिनमे आप Date Object को उपयोग कर सकते है. जैसे की यदि आप उपयोगकर्ता की पूरी Activity के बारे मे Information Store करना चाहते है तो ऐसा Date Object के माध्यम से कर सकते है. उपयोगकर्ता का Login Time, Logout Time, यदि उपयोगकर्ता ने कोई Update किया है तो उस समय को भी आप Date Object के माध्यम से Store कर सकते है.

Date Object को Construct करना होता है इसे आप सीधे उपयोग नहीं कर सकते है. इसलिए एक Date Object New Keyword द्वारा Create किया जाता है. Date Object को आप चार तरह से Create कर सकते है. पहले तरीके मे आप एक Normal Date Object Create करते है और उसमें कोई भी Value Pass नही करते है.

Syntax

new Date( )
new Date(milliseconds)
new Date(datestring)
new Date(year,month,date[,hour,minute,second,millisecond ])

Date Object Properties

JavaScript Date Object के साथ आपको दो Properties प्रदान करती है.

Property Description
Constructor

यह Property उस Function को Return करती है जिसके द्वारा Date Object Create किया गया है.

Prototype

इस Property के द्वारा आप Object मे अपनी Custom Properties और Methods Add करते है.

JavaScript Date Object

JavaScript Date Object के द्वारा Local Time के अनुसार दी गई Date और Month का Day प्राप्त करने के लिए उपयोग करते है.

For Example

<!DOCTYPE html>
<html>
   <head>
      <title>Date Object Example</title>
	</head>
   <body>
      <script type = "text/javascript">
         <!--
            var dt = Date();
            document.write("Date and Time : " + dt );
         //-->
      </script>
		
   </body>
</html>

Output

JavaScript getTime() Method

इसमे Local Time के अनुसार दी गई Date के Milliseconds को प्राप्त करने के लिये उपयोग करते है.

For Example

<!DOCTYPE html>
<html>
   <head>
      <title>JavaScript getTime() Example</title>
	</head>
   <body>
      <script type = "text/javascript">
         <!--
            var dt = new Date( "january 15, 2010 23:15:20" );
            document.write("getTime() : " + dt.getTime() );
         //-->
      </script>
		
   </body>
</html>

Output

JavaScript Digital Clock

<!DOCTYPE html>
<html>
   <head>
      <title>Digital Clock Example</title>
   </head>
   <body>
      Current Time: <span id="txt"></span>  
      <script type = "text/javascript">  
         window.onload=function(){getTime();}
         function getTime(){  
            var today=new Date();  
            var h=today.getHours();  
            var m=today.getMinutes();  
            var s=today.getSeconds();  
            // add a zero in front of numbers<10  
            m=checkTime(m);  
            s=checkTime(s);  
            document.getElementById('txt').innerHTML=h+":"+m+":"+s;  
            setTimeout(function(){getTime()},1000);  
         }  
         //setInterval("getTime()",1000);//another way  
         function checkTime(i){  
            if (i<10){  
               i="0" + i;  
            }  
            return i;  
         }  
      </script>  
   </body>
</html>

Output

Javascript in Hindi Form Validation

Forms के द्वारा उपयोगकर्ता से Information ली जाती है. लेकिन आपको ये जांच करना जरुरी है की उपयोगकर्ता ने जो Values Input की वो उपयुक्त है या नहीं है. Database मे हमेंशा Valid values होनी चाहिए इससे Processing मे कोई Difficulties नही आती है. यदि उपयोगकर्ता के द्वारा Input की गई Values उपयुक्त नहीं है तो उपयुक्त को एक Message Display किया जाता है और Valid Values Input करने के लिए कहा जाता है. यह Process Validation कहलाती है.

HTML मे Data को Validate करने का कोई तरीका नहीं है. Normally Validation जब उपयोगकर्ता Form को Submit कर देता है तो Server Side पर Perform किया जाता है. लेकिन JavaScript आपको Client Side Validation Perform करने की Ability प्रदान करती है.

Form Validation आमतौर पर दो Function पर Work करता है.

  • Basic Form Validation

  • JavaScript Validation with image

Basic Form Validation

किसी Form मे कुछ Fields ऐसे होते है जिनको Fill करना Necessary होता है जैसे की Name, Email आदि. यदि आप ये चाहते है की उपयोगकर्ता उस Necessary Field को Empty ना छोड़े तो इसके लिए आप उस Field पर Validation Perform कर सकते है. जब उपयोगकर्ता Form Submit करे तो आप Check कर सकते है की उस Necessary Field मे Value है या नही.

Value नही होने पर आप कोई Message Show कर सकते है. इसके लिए आप DOM का उपयोग कर सकते है क्योंकि Field मे कोई Value है या नहीं ये Dynamically Form Submit करते समय Check किया जायेगा. आप कोई Function Create कर सकते है जो की Submit Button के Click होने पर Call होगा और इसमे आप Document Object के द्वारा उस Field की Value को Check कर सकते है. इसे आपको उन्हीं Fields पर Apply करना चाहिए जिनमे Values डालना Necessary हो.

<!DOCTYPE html>
<html>
   <head>
      <title>Basic Form Validation Example</title>
   </head>
   <script type="text/javascript">
      function validateform(){  
         var name=document.myform.name.value;  
         var password=document.myform.password.value;  

         if (name==null || name==""){  
            alert("Name can't be blank");  
            return false;  
         }
         else if(password.length<6){  
            alert("Password must be at least 6 characters long.");  
            return false;  
         }  
      } 
   </script>	
   </body>
	
      <form name="myform" method="post" action="http://www.tutorialsroot.com" 
         onsubmit="return validateform()" >  
         Name: <input type="text" name="name">  
         Password: <input type="password" name="password">  
         <input type="submit" value="Submit">  
      </form>  
		
   </body>
</html>

Output

JavaScript Validation with Image

इसमे उपयोगकर्ता को बता दिया जाता है की उसकी Fill की गई जानकारी सही है या गलत.

<!DOCTYPE html>
<html>
   <head>
      <title>JavaScript validation with Image</title>
   </head>
   <script type="text/javascript">
      function validate(){  
         var name=document.f1.name.value;  
         var passwordlength=document.f1.password.value.length;  
         var status=false;  
         if(name==""){  
            document.getElementById("namelocation").innerHTML=  
            " <img src='http://tutorialsroot.com/css/images/syntex.jpg'/>
            Please enter your name";  
            status=false;
         }
         else
         {  
            document.getElementById("namelocation").innerHTML=" 
            <img src='http://tutorialsroot.com/css/images/syntex.jpg'/>";  
            status=true;
         }  

         if(passwordlength<6){  
            document.getElementById("passwordlocation").innerHTML=  
            " <img src='http://tutorialsroot.com/css/images/syntex.jpg'/>
            Password must be greater than 6";  
            status=false; 
         }
         else
         {  
            document.getElementById("passwordlocation").innerHTML=" 
            <img src='http://tutorialsroot.com/css/images/syntex.jpg'/>";  
         }  

         return status;  
      }  

   </script>
		
   </body>
	
      <form name="f1" action="#" onsubmit="return validate()">  
         <table>  
            <tr>
               <td>Enter Name:</td><td><input type="text" name="name"/>  
               <span id="nameloc"></span></td>
            </tr>  
            <tr>
               <td>Enter Password:</td><td><input type="password"
               name="password"/>  
               <span id="passwordloc"></span></td>
            </tr>  
            <tr>
               <td colspan="2"><input type="submit" value="Submit"/></td>
            </tr>  
         </table>  
      </form>    
		
   </body>
</html>

Output

Javascript in Hindi Animation

Animation Drawing, Layout, Photo और Designing करने की Sequence की एक प्रक्रिया है जो Multimedia और Gaming Products मे Integrate है. और Drive का भ्रम पैदा करने के लिए Animation मे अभी भी Images का Exploitation और Management शामिल होता है. एक व्यक्ति जो Animation को Design करता है उसे Animator कहा जाता है.

JavaScript Animation कुछ ऐसे Manufactures को भी संभाल सकता है जिनको CSS Control नही कर सकती है. CSS मे Animation Web पर एक महत्वपूर्ण भूमिका निभाते है जो कि विशेष रूप से CSS के Basic User Interaction से Related Simple Animation के लिए एक दम सही है.

एक Complex Animation को बनाने के लिए हम Javascript का प्रयोग करते है .

Manual Animation

एक आसान Animation को बनाने के लिये हम DOM Object Properties और JavaScript Functions का उपयोग करते है.

For Examples

<!DOCTYPE html>
<html>
   <head>
      <title>JavaScript Animation Examples</title>
      <script type="text/javascript">
         var imgObj = null;
         function init(){
            imgObj = document.getElementById('myImage');
            imgObj.style.position= 'relative'; 
            imgObj.style.left = '0px'; 
         }

         function moveRight(){
            imgObj.style.left = parseInt(imgObj.style.left) + 10 + 'px';
         }

         window.onload =init;

      </script>
   </head>
   <body>
   <h3>JavaScript Animation Examples</h3>
      <form>
         <img id="myImage" src="javascript.gif" />
         <p>Click button below to move the image to right</p>
         <input type="button" value="Click Me" onclick="moveRight();" />
      </form>   
   </body>
</html>

Output

Automated Animation

हम JavaScript Function से setTimeout() का उपयोग करके स्वचालित रूप से Automated Animation को Set कर सकते है.

For Examples

<!DOCTYPE html>
<html>
   <head>
      <title>Automated Animation Examples</title>
      <script type="text/javascript">
         var imgObj = null;
            var animate ;
            function init(){
               imgObj = document.getElementById('myImage');
               imgObj.style.position= 'relative'; 
               imgObj.style.left = '0px'; 
            }
            
            function moveRight(){
               imgObj.style.left = parseInt(imgObj.style.left) + 10 + 'px';
               animate = setTimeout(moveRight,20); // call moveRight in 20msec
            }
            
            function stop(){
               clearTimeout(animate);
               imgObj.style.left = '0px'; 
            }
            
            window.onload =init;
      </script>
   </head>	
   <body>
      <h3>Automated Animation Examples</h3>
      <form>
         <img id="myImage" src="javascript.gif" />
         <p>Click the buttons below to handle animation</p>
         <input type="button" value="Start" onclick="moveRight();" />
         <input type="button" value="Stop" onclick="stop();" />
      </form>   
   </body>
</html>

Output

Javascript in Hindi Image Map

Client Side मे Image Map को बनाने के लिए Javascript का उपयोग करते है. Javascript मे Hotspot Link प्रदान करने के लिए Shape, Rectangle, Circle, Polygon का उपयोग कर सकते है. यदि आप एक Rectangle Image का Map बनाना चाहते है तो आप दो अलग अलग Rules की आवश्यकता होगी.

Javascript मे Image Maps को Define करने के लिये MAP Element का उपयोग करते है. हर Image Maps का एक Unique Name होता है क्योंकि MAP Element मे Name Attribute की आवश्यकता होती है.

For Example

<!DOCTYPE html>
<html>
   <head>
      <title>JavaScript Image Map Example</title>
      <script type="text/javascript">
         <!--
            function showTutorial(name){
               document.myform.stage.value = name
            }
         //-->
      </script>
      
   </head>
   <body>
      <form name="myform">
         <input type="text" name="stage" size="20" />
      </form>
      
      <!-- Create  Mappings -->
      <img src="usemap.gif" alt="HTML Map" border="0" usemap="#tutorials"/>
      
      <map name="tutorials">
         <area shape="poly" 
            coords="74,0,113,29,98,72,52,72,38,27"
            href="/bootstrap/index.htm" alt="Bootstrap Tutorial"
            target="_self" 
            onMouseOver="showTutorial('Bootstrap')" 
            onMouseOut="showTutorial('')"/>
         
         <area shape="rect" 
            coords="22,83,126,125"
            href="/html/index.htm" alt="HTML Tutorial" 
            target="_self" 
            onMouseOver="showTutorial('html')" 
            onMouseOut="showTutorial('')"/>
         
         <area shape="circle" 
            coords="73,168,32"
            href="/php/index.htm" alt="PHP Tutorial"
            target="_self" 
            onMouseOver="showTutorial('php')" 
            onMouseOut="showTutorial('')"/>
      </map>
   </body>
</html>

Output

Javascript in Hindi Browsers

सभी Browsers के बीच के अंतर को समझना बहुत जरुरी होता है क्योकि प्रत्येक उपयोगकर्ता के मुताबिक आप इसे Maintenance कर सके. और हमारे लिये ये भी जानना बहुत जरुरी होता है की हमारा Web Page किस Browsers पर चल रहा है.

हमारा Web Page किस Browsers पर चल रहा है इसको जानने के लिये हम built-in Navigator Object का उपयोग करते है.

Navigator Properties

Navigator Properties बहुत सी होती है जिनका उपयोग आप अपने Web Page मे कर सकते है.

  • appCodeName

  • language

  • appVersion

  • platform[]

  • mimTypes[]

  • userAgent[]

  • plugins[]

  • userAgent[]

Navigator Methods

Navigator Methods मे बहुत से Specific Methods होते है जिनका उपयोग आप अपने Web Page मे कर सकते है.

  • javaEnabled()

  • taintEnabled()

  • plugings.refresh

  • preference(name,value)

Browser Detection

Browser के नाम को जानने के लिए हम आसान JavaScript का उपयोग करते है और उसके अनुसार User को एक HTML Page पर Served किया जा सकता है.

For Example

<!DOCTYPE html>
<html>
   <head>
      <title>Browser Detection Example</title>
   </head>
   <body> 
      <script type="text/javascript">
         <!--
            var userAgent   = navigator.userAgent;
            var opera       = (userAgent.indexOf('Opera') != -1);
            var ie          = (userAgent.indexOf('MSIE') != -1);
            var gecko       = (userAgent.indexOf('Gecko') != -1);
            var netscape    = (userAgent.indexOf('Mozilla') != -1);
            var version     = navigator.appVersion;
            
            if (opera){
               document.write("Opera based browser");
            }
            
            else if (gecko){
               document.write("Mozilla based browser");
            }
            
            else if (ie){
               document.write("IE based browser");
            }
            
            else if (netscape){
               document.write("Netscape based browser");
            }
            
            else{
               document.write("Unknown browser");
            }
            document.write("<br /> Browser version info : " + version );
         //-->
      </script> 
   </body>
</html>

Output

Javascript in Hindi Multimedia

JavaScript Navigator Object मे Child Object शामिल होते है जिनको Plug-ins कहा जाता है. और ये Object मूल रूप से एक Array मे होती है जिसमे हर Browser मे प्रत्येक Plug-ins को Installed किया जाता है.

For Example

<!DOCTYPE html>
<html>
   <head>
      <title>Javascript Multimedia Example</title>
      <style>
         table,th,td{border:1px solid red;}
      </style>
   </head>
   <body>
      <table>
         <tr>
            <th>Plug-in Name</th>
            <th>Filename</th>
            <th>Description</th>
         </tr>
         <script language="JavaScript" type="text/javascript">
            for (i=0; i<navigator.plugins.length; i++)
            {
               document.write("<tr><td>");
               document.write(navigator.plugins[i].name);
               document.write("</td><td>");
               document.write(navigator.plugins[i].filename);
               document.write("</td><td>");
               document.write(navigator.plugins[i].description);
               document.write("</td></tr>");
            }
         </script>
      </table>
   </body>
</html>

Output


Related Article in Hindi

वर्ल्ड वाइड वेब क्या है पूरी जानकारी हिन्दी में
सर्च इंजन क्या है और कैसे काम करता है
एपीआई क्या है और कैसे काम करता है
हैकर कैसे बने पूरी जानकारी हिन्दी में
यूआरएल क्या है यह कैसे काम करता है
इन्टरनेट कुकीज क्या है पूरी जानकारी हिन्दी में
डिजिटल सिग्नेचर क्या है पूरी जानकारी हिन्दी में
वेब होस्टिंग क्या है और कैसे काम करती है
डेटाबेस क्या होता है पूरी जानकारी हिन्दी में
ली.फी क्या है यह काम कैसे करता है
एफ़टीपी क्या है पूरी जानकारी हिन्दी में
इन्टरनेट ऑफ़ थिंग्स क्या है पूरी जानकारी हिन्दी में
पेपैल क्या है पूरी जानकारी हिन्दी में
डोमेन नाम क्या है पूरी जानकारी हिन्दी में
प्रॉक्सी सर्वर क्या है पूरी जानकारी हिन्दी में
वेब ब्राउज़र क्या है और कैसे काम करता है
वेब सर्वर क्या है पूरी जानकारी हिन्दी में
IP एड्रेस क्या है पूरी जानकारी हिन्दी में
Captcha Code क्या है पूरी जानकारी हिन्दी में
नेटवर्क हब क्या है पूरी जानकारी हिन्दी में
बिटकॉइन क्या है पूरी जानकारी हिन्दी में
Kali Linux क्या है जानिए हिंदी में
हैशटैग (#) क्या होता है जाने हिंदी में
स्विच और राऊटर में क्या अंतर है
Deep Web/Dark Web/Surface Web क्या है
Affiliate Marketing क्या है पूरी जानकारी हिन्दी में
DDoS attack क्या होता है पूरी जानकारी हिन्दी में
Mirror Server Mirror Website क्या होती है
ATM Card, Debit Card, Credit Card में क्या अंतर
ऑपरेटिंग सिस्टम क्या है पूरी जानकारी हिंदी में