You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This part of the tutorial is about core JavaScript, the language itself.
3
+
ٹیوٹوریل کا یہ حصہ Javascript کی بنیاد ہے۔ Javascript زبان کا سبق ہے یہ۔
4
4
5
-
But we need a working environment to run our scripts and, since this book is online, the browser is a good choice. We'll keep the amount of browser-specific commands (like `alert`) to a minimum so that you don't spend time on them if you plan to concentrate on another environment (like Node.js). We'll focus on JavaScript in the browser in the [next part](/ui) of the tutorial.
6
-
7
-
So first, let's see how we attach a script to a webpage. For server-side environments (like Node.js), you can execute the script with a command like `"node my.js"`.
5
+
لیکن ہمیں اپنی سکرپٹس چلانے کیلیے کسی انوائرنمنٹ کی ضرورت ہے۔ چونکہ یہ کتاب آن لائن ہے تو براؤزر ہی ایک اچھا انتخاب ہے۔ ہم براؤزر کے متعلق کمانڈز (جیسے کہ `alert` ہے) کو کم سے کم استعمال کریں گے تاکہ اگر آپ کسی دوسرے انوائرنمنٹ جیسے (Node JS ہے) پر کام کرنا چاہیں تو آپ کو بہت زیادہ مشکل نہ ہو۔ ہم [اگلے حصے](/ui) میں Javascript کو براؤزر میں استعمال کرنے پر غور کریں گے۔
8
6
7
+
تو پہلے دیکھتے ہیں کہ ایک سکرپٹ کو ایک ویب پیج کے ساتھ کیسے جوڑا جاتا ہے۔ server-side انوائرنمنٹ (جیسے Node ہے) پر سکرپٹ چلانے کیلیے ایک کمانڈ جیسے `"node my.js"` ہے کو چلایا جائے گا۔
9
8
10
9
## The "script" tag
11
10
12
-
JavaScript programs can be inserted almost anywhere into an HTML document using the `<script>` tag.
11
+
جاواسکرپٹ (Javascript) پروگرامز کو HTML ڈاکیومنٹ میں کہیں بھی `<script>` tag شاھل کیا جا سکتا ہے۔
13
12
14
-
For instance:
13
+
مثال کے طور پر:
15
14
16
15
```html run height=100
17
16
<!DOCTYPE HTML>
18
17
<html>
19
18
20
19
<body>
21
20
22
-
<p>Before the script...</p>
21
+
<p>سکرپٹ سے پہلے۔۔۔</p>
23
22
24
23
*!*
25
24
<script>
26
25
alert( 'Hello, world!' );
27
26
</script>
28
27
*/!*
29
28
30
-
<p>...After the script.</p>
29
+
<p>سکرپٹ کے بعد۔۔۔</p>
31
30
32
31
</body>
33
32
34
33
</html>
35
34
```
36
35
37
36
```online
38
-
You can run the example by clicking the "Play" button in the right-top corner of the box above.
37
+
آپ مثال کو چلانے کیلیے ڈبے کے سب سے اوپر دائیں کونے میں "Play" کے بٹن کو دبا سکتے ہیں۔
39
38
```
40
39
41
-
The `<script>` tag contains JavaScript code which is automatically executed when the browser processes the tag.
42
-
40
+
`<script>` tag میں موجود Javascript کوڈ براؤزر کے tag کو پروسیس کرنے پر خود بخود چل جاتا ہے۔
43
41
44
42
## Modern markup
45
43
46
-
The `<script>` tag has a few attributes that are rarely used nowadays but can still be found in old code:
44
+
`<script>` tag کے کچھ attributes ہیں جو آج کل مشکل ہی استعمال کیجیے جاتے ہیں لیکن پرانے کوڈ میں ابھی بھی موجود ہیں:
The `type` attribute: <code><script <u>type</u>=...></code>
49
-
: The old HTML standard, HTML4, required a script to have a `type`. Usually it was `type="text/javascript"`. It's not required anymore. Also, the modern HTML standard totally changed the meaning of this attribute. Now, it can be used for JavaScript modules. But that's an advanced topic, we'll talk about modules in another part of the tutorial.
48
+
: پرانے HTML standard, HTML4 میں سکرپٹ tag کے اوپر `type` attribute کا ہونا لازمی تھا۔ عام طور پر یہ `type="text/javascript"` ہوتا تھا۔ اب یہ لازم نہیں ہے۔ جدید HTML standard نے اسکا مطلب بھی بدل دیا ہے۔ اب یہ Javascript موڈیولز کیلیے استعمال ہو سکتا ہے۔ لیکن وہ ایک اعلی درجے کا موضوع ہے۔ ہم اس کے بارے ٹیوٹوریل کے موڈیولز کے حصے میں بات کریں گے۔
50
49
51
-
The `language` attribute: <code><script <u>language</u>=...></code>
52
-
: This attribute was meant to show the language of the script. This attribute no longer makes sense because JavaScript is the default language. There is no need to use it.
: یہ attribute سکرپٹ کی زبان دکھانے کیلیے استعمال ہوتا تھا۔ اب یہ attribute کسی کام کا نہیں کیونکہ Javascript ڈیفالٹ زبان ہے۔ اسے استعمال کرنے کی کوئی ضرورت نہیں۔
53
52
54
-
Comments before and after scripts.
55
-
: In really ancient books and guides, you may find comments inside `<script>` tags, like this:
53
+
سکرپٹس کے پہلے اور بعد میں کمنٹس۔
54
+
: پرانی کتابوں اور گائیڈز میں آپ کو `<script>` tags میں اس طرح کمنٹ ملتے ہوں گے:
56
55
57
56
```html no-beautify
58
57
<script type="text/javascript"><!--
59
58
...
60
59
//--></script>
61
60
```
62
-
63
-
This trick isn't used in modern JavaScript. These comments hide JavaScript code from old browsers that didn't know how to process the `<script>` tag. Since browsers released in the last 15 years don't have this issue, this kind of comment can help you identify really old code.
61
+
یہ طریقہ جدید Javascript میں استعمال نہیں کیا جاتا۔ یہ کمنٹس Javascript کوڈ کو پرابے براؤزرز جنہیں یہ معلوم نہیں کہ `<script>` tag کو کس طرح پروسیس کرنا ہے سے چھپا دیتے ہیں۔ چونکہ پچھلے 15 سالوں میں جو براؤزرز ریلیز کیے جا رہے ہیں ان میں یہ مسؑلہ نہیں اس کمنٹ سے آپ کے ایک بہت پرانے کوڈ کی شناخت کرنے میں مدد ملے گی۔
64
62
65
63
66
64
## External scripts
67
65
68
-
If we have a lot of JavaScript code, we can put it into a separate file.
66
+
اگر ہمارے پاس بہت زیادہ جاواسکرپٹ کوڈ ہو تو ہم اسے علیحدہ فائل میں شامل کر سکتے ہیں۔
69
67
70
-
Script files are attached to HTML with the`src` attribute:
68
+
سکرپٹ فائلز کو HTML کے ساتھ`src` attribute سے جوڑا جاتا ہے۔
71
69
72
70
```html
73
71
<scriptsrc="/path/to/script.js"></script>
74
72
```
75
73
76
-
Here,`/path/to/script.js`is an absolute path to the script from the site root. One can also provide a relative path from the current page. For instance, `src="script.js"`, just like`src="./script.js"`, would mean a file `"script.js"`in the current folder.
74
+
یہاں`/path/to/script.js`سکرپٹ کا سائٹ کے روٹ سے ایبسولیوٹ پاتھ ہے۔ ہم موجودہ پیج سے ریلیٹِو پاتھ بھی مہیا کر سکتے ہیں۔ مثال کے طور پر، `src="script.js"`، اسی طرح`src="./script.js"` کا مطلب بھی یہ ہی ہے کہ موجودہ فولڈر میں موجود `"script.js"`نام کی فائل۔
کئی سکرپٹس شامل کرنے کیلیے ایک سے زیادہ tags استعمال کیے جاتے ہیں:
85
83
86
84
```html
87
85
<scriptsrc="/js/script1.js"></script>
@@ -90,29 +88,29 @@ To attach several scripts, use multiple tags:
90
88
```
91
89
92
90
```smart
93
-
As a rule, only the simplest scripts are put into HTML. More complex ones reside in separate files.
91
+
اصول کے مطابق، صرف سادہ ترین سکرپٹس ہی HTML میں لکھی جاتی ہے۔ زیادہ پیچیدہ سکرپٹس کو علیحدہ فائلز میں رکھا جاتا ہے۔
94
92
95
-
The benefit of a separate file is that the browser will download it and store it in its [cache](https://en.wikipedia.org/wiki/Web_cache).
93
+
علیحدہ فائل کا فائدہ یہ ہے کہ براؤزر اسے ڈاؤن لوڈ کرنے کے بعد اپنے [cache](https://en.wikipedia.org/wiki/Web_cache) میں محفوظ کر لے گا۔
96
94
97
-
Other pages that reference the same script will take it from the cache instead of downloading it, so the file is actually downloaded only once.
95
+
دوسرے پیجز جو اسی سکرپٹ کو حوالہ استعمال کریں گے وہ اسے ڈاؤن لوڈ کرنے کی جگہ کیش سے اٹھائیں گے۔ اس طرح فائل صرف ایک دفعہ ہی ڈاؤن لوڈ ہوتی ہے اور اسی فائل کا استعمال بار بار ہوتا ہے۔
98
96
99
-
That reduces traffic and makes pages faster.
97
+
اس سے ٹریفک کم ہوتی ہے اور پیج تیز ہو جاتا ہے۔
100
98
```
101
99
102
100
````warn header="If `src` is set, the script content is ignored."
103
-
A single`<script>` tag can't have both the`src` attribute and code inside.
101
+
ایک اکیلا`<script>` tag اپنے اندر کوڈ اور`src` attribute دونوں نہیں رکھ سکتا۔
104
102
105
-
This won't work:
103
+
یہ کوڈ کام نہیں کرے گا:
106
104
107
105
```html
108
106
<script*!*src*/!*="file.js">
109
-
alert(1); //the content is ignored, because src is set
107
+
alert(1); //کنٹینٹ اگنور کر دیا جاتا ہے، کیونکہ سورس موجود ہے۔
110
108
</script>
111
109
```
112
110
113
-
We must choose either an external `<script src="…">`or a regular `<script>`with code.
111
+
ہمیں بیرونی `<script src"...">`یا اندرونی `<script>`سکرپٹ میں سے کوئی ایک لازمی چننا ہوتی ہے۔
114
112
115
-
The example above can be split into two scripts to work:
113
+
مندرجہ بالا مثال کو دو سکرپٹس میں تقسیم کر کے استعمال کیا جا سکتا ہے:
116
114
117
115
```html
118
116
<scriptsrc="file.js"></script>
@@ -123,10 +121,10 @@ The example above can be split into two scripts to work:
123
121
````
124
122
125
123
## Summary
124
+
- ہم `<script>` tag استعمال کرکے Javascript کوڈ کو پیج میں شامل کر سکتے ہیں۔
125
+
- `type` اور `language` attributes لازم نہیں۔
126
+
- بیرونی سکرپٹ کو `<script src="path/to/script.js"></script>` کی مدد سے شامل کیا جا سکتا ہے۔
126
127
127
-
- We can use a `<script>` tag to add JavaScript code to a page.
128
-
- The `type` and `language` attributes are not required.
129
-
- A script in an external file can be inserted with `<script src="path/to/script.js"></script>`.
130
-
128
+
براؤزر سکرپٹس کے بارے اور ان کی ویب پیج کے ساتھ interaction کے بارے بہت کچھ سیکھنے کو ہے۔ لیکن ذہن نشین رکھیے کہ ٹیوٹوریل کا یہ حصہ Javascript زبان کیلیے مخصوص ہے۔
131
129
132
130
There is much more to learn about browser scripts and their interaction with the webpage. But let's keep in mind that this part of the tutorial is devoted to the JavaScript language, so we shouldn't distract ourselves with browser-specific implementations of it. We'll be using the browser as a way to run JavaScript, which is very convenient for online reading, but only one of many.
0 commit comments