diff --git a/html/arabic/java/advanced-usage/_index.md b/html/arabic/java/advanced-usage/_index.md index 5fd516250..659669659 100644 --- a/html/arabic/java/advanced-usage/_index.md +++ b/html/arabic/java/advanced-usage/_index.md @@ -136,6 +136,9 @@ weight: 20 ### [كيفية تشغيل JavaScript في Java – دليل كامل](./how-to-run-javascript-in-java-complete-guide/) تعلم كيفية تشغيل كود JavaScript داخل تطبيقات Java باستخدام Aspose.HTML for Java. +### [كيفية تمكين JavaScript في Java – دليل Aspose.HTML الكامل](./how-to-enable-javascript-in-java-complete-aspose-html-guide/) +اكتشف طريقة تمكين JavaScript في تطبيقات Java باستخدام Aspose.HTML for Java بسهولة. + --- **آخر تحديث:** 2025-11-29 diff --git a/html/arabic/java/advanced-usage/how-to-enable-javascript-in-java-complete-aspose-html-guide/_index.md b/html/arabic/java/advanced-usage/how-to-enable-javascript-in-java-complete-aspose-html-guide/_index.md new file mode 100644 index 000000000..68a5ecfa4 --- /dev/null +++ b/html/arabic/java/advanced-usage/how-to-enable-javascript-in-java-complete-aspose-html-guide/_index.md @@ -0,0 +1,216 @@ +--- +category: general +date: 2026-02-22 +description: كيفية تمكين JavaScript في Java باستخدام Aspose.HTML. تعلم تشغيل JavaScript + في Java، قراءة عنصر حسب المعرف (ID)، استرجاع النص الداخلي للعنصر، وتحميل مستند HTML + في Java. +draft: false +keywords: +- how to enable javascript +- run javascript in java +- read element by id +- retrieve element inner text +- load html document java +language: ar +og_description: كيفية تمكين JavaScript في Java باستخدام Aspose.HTML. كود خطوة بخطوة + لتشغيل JavaScript في Java، قراءة العنصر بواسطة المعرف (ID) واسترجاع النص الداخلي + للعنصر. +og_title: كيفية تمكين JavaScript في Java – دليل Aspose.HTML الكامل +tags: +- Aspose.HTML +- Java +- Scripting +title: كيفية تمكين JavaScript في Java – دليل Aspose.HTML الكامل +url: /ar/java/advanced-usage/how-to-enable-javascript-in-java-complete-aspose-html-guide/ +--- + +{{< blocks/products/pf/main-wrap-class >}} +{{< blocks/products/pf/main-container >}} +{{< blocks/products/pf/tutorial-page-section >}} + +# كيفية تمكين JavaScript في Java – دليل Aspose.HTML الكامل + +هل تساءلت يومًا **كيف تمكّن JavaScript في Java** عند معالجة HTML على جانب الخادم؟ ربما واجهت صعوبة في تقييم سكريبت صغير يحدد النص الذي يُعرض على الصفحة. الخبر السار هو أنك لست بحاجة إلى تشغيل متصفح كامل—Aspose.HTML يتيح لك تشغيل JavaScript مباشرة داخل تطبيق Java. + +في هذا الدرس سنستعرض خطوات تحميل مستند HTML، تشغيل محرك JavaScript، ثم استخراج النتيجة من عنصر باستخدام معرّفه (ID). بحلول النهاية ستكون قادرًا على **run JavaScript in Java**، **read element by ID**، و**retrieve element inner text** دون عناء. + +> **ما ستحصل عليه:** فئة Java جاهزة للنسخ، شروحات لأهمية كل سطر، ونصائح للتعامل مع الحالات الخاصة مثل تعطيل السكريبت أو العناصر الفارغة (null). + +--- + +![مثال على كيفية تمكين JavaScript في Java](image.png "كيفية تمكين javascript في java") + +## المتطلبات المسبقة + +- Java 8 أو أحدث (API يعمل مع أي JDK حديث) +- مكتبة Aspose.HTML for Java (حمّل أحدث JAR من موقع Aspose) +- ملف HTML صغير (`script_demo.html`) يحتوي على تعبير JavaScript، مثال: + +```html + + +Demo + +
+ + + +``` + +تأكد من أن الملف موجود في موقع يمكن لعملية Java قراءته—`YOUR_DIRECTORY/script_demo.html` في الشيفرة أدناه. + +--- + +## الخطوة 1: تحميل مستند HTML في Java + +أول شيء تحتاجه هو كائن `HTMLDocument` يشير إلى ملفك. يمكن للمنشئ في Aspose.HTML قبول كائن `ScriptEngineOptions`، مما يمنحك التحكم في بيئة السكريبت. + +```java +import com.aspose.html.HTMLDocument; +import com.aspose.html.scripting.ScriptEngineOptions; + +public class JsEngineDemo { + public static void main(String[] args) throws Exception { + + // Load the HTML file – this also prepares the DOM for script execution + HTMLDocument htmlDoc = new HTMLDocument("YOUR_DIRECTORY/script_demo.html"); + // ... we’ll configure the engine in the next step + } +} +``` + +**لماذا هذا مهم:** تحميل المستند يحلل العلامات ويبني شجرة DOM. حتى تقوم بتمكين محرك السكريبت، سيتم تجاهل أي كتل ` + + +``` + +确保该文件位于 Java 进程可读取的位置——代码中使用的路径为 `YOUR_DIRECTORY/script_demo.html`。 + +--- + +## 第一步:在 Java 中加载 HTML 文档 + +首先需要一个指向文件的 `HTMLDocument` 实例。Aspose.HTML 的构造函数可以接受 `ScriptEngineOptions` 对象,从而让你控制脚本环境。 + +```java +import com.aspose.html.HTMLDocument; +import com.aspose.html.scripting.ScriptEngineOptions; + +public class JsEngineDemo { + public static void main(String[] args) throws Exception { + + // Load the HTML file – this also prepares the DOM for script execution + HTMLDocument htmlDoc = new HTMLDocument("YOUR_DIRECTORY/script_demo.html"); + // ... we’ll configure the engine in the next step + } +} +``` + +**为什么这很重要:** 加载文档会解析标记并构建 DOM 树。在启用脚本引擎之前,所有 ` + + +``` + +Ujistěte se, že soubor je umístěn na místě, kde jej může Java proces číst – `YOUR_DIRECTORY/script_demo.html` v níže uvedeném kódu. + +--- + +## Krok 1: Načtení HTML dokumentu v Javě + +Prvním, co potřebujete, je instance `HTMLDocument`, která ukazuje na váš soubor. Konstruktor Aspose.HTML může přijmout objekt `ScriptEngineOptions`, který vám dává kontrolu nad skriptovacím prostředím. + +```java +import com.aspose.html.HTMLDocument; +import com.aspose.html.scripting.ScriptEngineOptions; + +public class JsEngineDemo { + public static void main(String[] args) throws Exception { + + // Load the HTML file – this also prepares the DOM for script execution + HTMLDocument htmlDoc = new HTMLDocument("YOUR_DIRECTORY/script_demo.html"); + // ... we’ll configure the engine in the next step + } +} +``` + +**Proč je to důležité:** Načtení dokumentu parsuje značky a vytvoří strom DOM. Dokud nepovolíte skriptovací engine, všechny bloky ` + + +``` + +Zorg ervoor dat het bestand zich bevindt op een locatie die je Java‑proces kan lezen—`YOUR_DIRECTORY/script_demo.html` in de code hieronder. + +--- + +## Stap 1: HTML‑document laden in Java + +Het eerste wat je nodig hebt is een `HTMLDocument`‑instantie die naar je bestand wijst. De constructor van Aspose.HTML kan een `ScriptEngineOptions`‑object accepteren, waarmee je controle hebt over de scripting‑omgeving. + +```java +import com.aspose.html.HTMLDocument; +import com.aspose.html.scripting.ScriptEngineOptions; + +public class JsEngineDemo { + public static void main(String[] args) throws Exception { + + // Load the HTML file – this also prepares the DOM for script execution + HTMLDocument htmlDoc = new HTMLDocument("YOUR_DIRECTORY/script_demo.html"); + // ... we’ll configure the engine in the next step + } +} +``` + +**Waarom dit belangrijk is:** Het laden van het document parseert de markup en bouwt een DOM‑boom. Totdat je de script‑engine inschakelt, worden ` + + +``` + +Make sure the file lives somewhere your Java process can read—`YOUR_DIRECTORY/script_demo.html` in the code below. + +--- + +## Step 1: Load HTML Document in Java + +The first thing you need is an `HTMLDocument` instance that points at your file. Aspose.HTML’s constructor can accept a `ScriptEngineOptions` object, which gives you control over the scripting environment. + +```java +import com.aspose.html.HTMLDocument; +import com.aspose.html.scripting.ScriptEngineOptions; + +public class JsEngineDemo { + public static void main(String[] args) throws Exception { + + // Load the HTML file – this also prepares the DOM for script execution + HTMLDocument htmlDoc = new HTMLDocument("YOUR_DIRECTORY/script_demo.html"); + // ... we’ll configure the engine in the next step + } +} +``` + +**Why this matters:** Loading the document parses the markup and builds a DOM tree. Until you enable the script engine, any ` + + +``` + +Assurez‑vous que le fichier se trouve à un endroit accessible à votre processus Java — `YOUR_DIRECTORY/script_demo.html` dans le code ci‑dessous. + +--- + +## Étape 1 : Charger le document HTML en Java + +La première chose dont vous avez besoin est une instance `HTMLDocument` qui pointe vers votre fichier. Le constructeur d’Aspose.HTML peut accepter un objet `ScriptEngineOptions`, ce qui vous donne le contrôle sur l’environnement de script. + +```java +import com.aspose.html.HTMLDocument; +import com.aspose.html.scripting.ScriptEngineOptions; + +public class JsEngineDemo { + public static void main(String[] args) throws Exception { + + // Load the HTML file – this also prepares the DOM for script execution + HTMLDocument htmlDoc = new HTMLDocument("YOUR_DIRECTORY/script_demo.html"); + // ... we’ll configure the engine in the next step + } +} +``` + +**Pourquoi c’est important :** Le chargement du document analyse le balisage et construit un arbre DOM. Tant que vous n’avez pas activé le moteur de script, les blocs ` + + +``` + +Stellen Sie sicher, dass die Datei an einem Ort liegt, den Ihr Java‑Prozess lesen kann – `YOUR_DIRECTORY/script_demo.html` im nachfolgenden Code. + +--- + +## Schritt 1: HTML‑Dokument in Java laden + +Das Erste, was Sie benötigen, ist eine `HTMLDocument`‑Instanz, die auf Ihre Datei zeigt. Der Konstruktor von Aspose.HTML kann ein `ScriptEngineOptions`‑Objekt entgegennehmen, das Ihnen die Kontrolle über die Skript‑Umgebung gibt. + +```java +import com.aspose.html.HTMLDocument; +import com.aspose.html.scripting.ScriptEngineOptions; + +public class JsEngineDemo { + public static void main(String[] args) throws Exception { + + // Load the HTML file – this also prepares the DOM for script execution + HTMLDocument htmlDoc = new HTMLDocument("YOUR_DIRECTORY/script_demo.html"); + // ... we’ll configure the engine in the next step + } +} +``` + +**Warum das wichtig ist:** Das Laden des Dokuments analysiert das Markup und baut einen DOM‑Baum auf. Solange Sie die Skript‑Engine nicht aktivieren, werden ` + + +``` + +Βεβαιωθείτε ότι το αρχείο βρίσκεται κάπου που η διαδικασία Java μπορεί να το διαβάσει — `YOUR_DIRECTORY/script_demo.html` στον κώδικα παρακάτω. + +--- + +## Βήμα 1: Φόρτωση Εγγράφου HTML στη Java + +Το πρώτο που χρειάζεστε είναι μια παρουσία `HTMLDocument` που δείχνει στο αρχείο σας. Ο κατασκευαστής του Aspose.HTML μπορεί να δεχτεί ένα αντικείμενο `ScriptEngineOptions`, το οποίο σας δίνει έλεγχο στο περιβάλλον scripting. + +```java +import com.aspose.html.HTMLDocument; +import com.aspose.html.scripting.ScriptEngineOptions; + +public class JsEngineDemo { + public static void main(String[] args) throws Exception { + + // Load the HTML file – this also prepares the DOM for script execution + HTMLDocument htmlDoc = new HTMLDocument("YOUR_DIRECTORY/script_demo.html"); + // ... we’ll configure the engine in the next step + } +} +``` + +**Γιατί είναι σημαντικό:** Η φόρτωση του εγγράφου αναλύει το markup και δημιουργεί ένα δέντρο DOM. Μέχρι να ενεργοποιήσετε τη μηχανή script, τυχόν μπλοκ ` + + +``` + +सुनिश्चित करें कि फ़ाइल ऐसी जगह पर हो जहाँ आपका Java प्रोसेस पढ़ सके—नीचे दिए गए कोड में `YOUR_DIRECTORY/script_demo.html`। + +--- + +## चरण 1: Java में HTML दस्तावेज़ लोड करें + +पहले आपको एक `HTMLDocument` इंस्टेंस चाहिए जो आपकी फ़ाइल की ओर इशारा करता हो। Aspose.HTML का कंस्ट्रक्टर एक `ScriptEngineOptions` ऑब्जेक्ट स्वीकार कर सकता है, जो आपको स्क्रिप्टिंग पर्यावरण पर नियंत्रण देता है। + +```java +import com.aspose.html.HTMLDocument; +import com.aspose.html.scripting.ScriptEngineOptions; + +public class JsEngineDemo { + public static void main(String[] args) throws Exception { + + // Load the HTML file – this also prepares the DOM for script execution + HTMLDocument htmlDoc = new HTMLDocument("YOUR_DIRECTORY/script_demo.html"); + // ... we’ll configure the engine in the next step + } +} +``` + +**यह क्यों महत्वपूर्ण है:** दस्तावेज़ को लोड करने से मार्कअप पार्स होता है और DOM ट्री बनता है। जब तक आप स्क्रिप्ट इंजन को सक्षम नहीं करते, सभी ` + + +``` + +確保該檔案位於 Java 程序可讀取的路徑——以下程式碼中的 `YOUR_DIRECTORY/script_demo.html`。 + +--- + +## 第一步:在 Java 中載入 HTML Document + +首先需要一個指向檔案的 `HTMLDocument` 實例。Aspose.HTML 的建構子可以接受 `ScriptEngineOptions` 物件,讓你掌控腳本執行環境。 + +```java +import com.aspose.html.HTMLDocument; +import com.aspose.html.scripting.ScriptEngineOptions; + +public class JsEngineDemo { + public static void main(String[] args) throws Exception { + + // Load the HTML file – this also prepares the DOM for script execution + HTMLDocument htmlDoc = new HTMLDocument("YOUR_DIRECTORY/script_demo.html"); + // ... we’ll configure the engine in the next step + } +} +``` + +**為什麼這很重要:** 載入文件會解析標記並建立 DOM 樹。除非啟用腳本引擎,否則所有 ` + + +``` + +Győződj meg róla, hogy a fájl olyan helyen van, ahová a Java folyamatod olvasni tud—`YOUR_DIRECTORY/script_demo.html` a lenti kódban. + +--- + +## 1. lépés: HTML dokumentum betöltése Java-ban + +Az első dolog, amire szükséged van, egy `HTMLDocument` példány, amely a fájlodra mutat. Az Aspose.HTML konstruktora elfogadhat egy `ScriptEngineOptions` objektumot, amely a szkriptkörnyezet feletti irányítást adja. + +```java +import com.aspose.html.HTMLDocument; +import com.aspose.html.scripting.ScriptEngineOptions; + +public class JsEngineDemo { + public static void main(String[] args) throws Exception { + + // Load the HTML file – this also prepares the DOM for script execution + HTMLDocument htmlDoc = new HTMLDocument("YOUR_DIRECTORY/script_demo.html"); + // ... we’ll configure the engine in the next step + } +} +``` + +**Miért fontos:** A dokumentum betöltése elemzi a jelölőnyelvet és felépíti a DOM-fát. Amíg nem engedélyezed a szkriptmotort, minden ` + + +``` + +Pastikan file tersebut berada di lokasi yang dapat dibaca oleh proses Java Anda—`YOUR_DIRECTORY/script_demo.html` dalam kode di bawah. + +--- + +## Langkah 1: Muat Dokumen HTML di Java + +Hal pertama yang Anda butuhkan adalah instance `HTMLDocument` yang menunjuk ke file Anda. Konstruktor Aspose.HTML dapat menerima objek `ScriptEngineOptions`, yang memberi Anda kontrol atas lingkungan skrip. + +```java +import com.aspose.html.HTMLDocument; +import com.aspose.html.scripting.ScriptEngineOptions; + +public class JsEngineDemo { + public static void main(String[] args) throws Exception { + + // Load the HTML file – this also prepares the DOM for script execution + HTMLDocument htmlDoc = new HTMLDocument("YOUR_DIRECTORY/script_demo.html"); + // ... we’ll configure the engine in the next step + } +} +``` + +**Mengapa ini penting:** Memuat dokumen mem-parsing markup dan membangun pohon DOM. Sampai Anda mengaktifkan mesin skrip, semua blok ` + + +``` + +Assicurati che il file si trovi in una posizione leggibile dal tuo processo Java—`YOUR_DIRECTORY/script_demo.html` nel codice qui sotto. + +--- + +## Passo 1: Caricare il documento HTML in Java + +La prima cosa di cui hai bisogno è un'istanza di `HTMLDocument` che punti al tuo file. Il costruttore di Aspose.HTML può accettare un oggetto `ScriptEngineOptions`, che ti dà il controllo sull'ambiente di scripting. + +```java +import com.aspose.html.HTMLDocument; +import com.aspose.html.scripting.ScriptEngineOptions; + +public class JsEngineDemo { + public static void main(String[] args) throws Exception { + + // Load the HTML file – this also prepares the DOM for script execution + HTMLDocument htmlDoc = new HTMLDocument("YOUR_DIRECTORY/script_demo.html"); + // ... we’ll configure the engine in the next step + } +} +``` + +**Perché è importante:** il caricamento del documento analizza il markup e costruisce un albero DOM. Finché non attivi il motore script, tutti i blocchi ` + + +``` + +ファイルがJavaプロセスから読み取れる場所にあることを確認してください—以下のコードでは `YOUR_DIRECTORY/script_demo.html` を使用しています。 + +--- + +## 手順 1: JavaでHTMLドキュメントを読み込む + +最初に必要なのは、ファイルを指す `HTMLDocument` インスタンスです。Aspose.HTML のコンストラクタは `ScriptEngineOptions` オブジェクトを受け取ることができ、スクリプト環境を制御できます。 + +```java +import com.aspose.html.HTMLDocument; +import com.aspose.html.scripting.ScriptEngineOptions; + +public class JsEngineDemo { + public static void main(String[] args) throws Exception { + + // Load the HTML file – this also prepares the DOM for script execution + HTMLDocument htmlDoc = new HTMLDocument("YOUR_DIRECTORY/script_demo.html"); + // ... we’ll configure the engine in the next step + } +} +``` + +**なぜ重要か:** ドキュメントを読み込むことでマークアップが解析され、DOMツリーが構築されます。スクリプトエンジンを有効にするまで、` + + +``` + +파일이 Java 프로세스가 읽을 수 있는 위치에 있어야 합니다—아래 코드에서는 `YOUR_DIRECTORY/script_demo.html`을 사용합니다. + +--- + +## Step 1: Load HTML Document in Java + +먼저 파일을 가리키는 `HTMLDocument` 인스턴스를 만들어야 합니다. Aspose.HTML의 생성자는 `ScriptEngineOptions` 객체를 받을 수 있으며, 이를 통해 스크립팅 환경을 제어할 수 있습니다. + +```java +import com.aspose.html.HTMLDocument; +import com.aspose.html.scripting.ScriptEngineOptions; + +public class JsEngineDemo { + public static void main(String[] args) throws Exception { + + // Load the HTML file – this also prepares the DOM for script execution + HTMLDocument htmlDoc = new HTMLDocument("YOUR_DIRECTORY/script_demo.html"); + // ... we’ll configure the engine in the next step + } +} +``` + +**왜 중요한가:** 문서를 로드하면 마크업을 파싱하고 DOM 트리를 구축합니다. 스크립트 엔진을 활성화하기 전까지는 ` + + +``` + +Upewnij się, że plik znajduje się w miejscu dostępnym dla procesu Java — `YOUR_DIRECTORY/script_demo.html` w poniższym kodzie. + +--- + +## Krok 1: Załaduj dokument HTML w Javie + +Pierwszą rzeczą, której potrzebujesz, jest instancja `HTMLDocument` wskazująca na Twój plik. Konstruktor Aspose.HTML może przyjąć obiekt `ScriptEngineOptions`, który daje kontrolę nad środowiskiem skryptowym. + +```java +import com.aspose.html.HTMLDocument; +import com.aspose.html.scripting.ScriptEngineOptions; + +public class JsEngineDemo { + public static void main(String[] args) throws Exception { + + // Load the HTML file – this also prepares the DOM for script execution + HTMLDocument htmlDoc = new HTMLDocument("YOUR_DIRECTORY/script_demo.html"); + // ... we’ll configure the engine in the next step + } +} +``` + +**Dlaczego to ważne:** Ładowanie dokumentu parsuje znacznik i buduje drzewo DOM. Dopóki nie włączysz silnika skryptów, wszystkie bloki ` + + +``` + +Certifique‑se de que o arquivo esteja em um local que seu processo Java possa ler—`YOUR_DIRECTORY/script_demo.html` no código abaixo. + +--- + +## Etapa 1: Carregar o documento HTML em Java + +A primeira coisa que você precisa é uma instância de `HTMLDocument` que aponte para o seu arquivo. O construtor do Aspose.HTML pode aceitar um objeto `ScriptEngineOptions`, que lhe dá controle sobre o ambiente de script. + +```java +import com.aspose.html.HTMLDocument; +import com.aspose.html.scripting.ScriptEngineOptions; + +public class JsEngineDemo { + public static void main(String[] args) throws Exception { + + // Load the HTML file – this also prepares the DOM for script execution + HTMLDocument htmlDoc = new HTMLDocument("YOUR_DIRECTORY/script_demo.html"); + // ... we’ll configure the engine in the next step + } +} +``` + +**Por que isso importa:** Carregar o documento analisa a marcação e constrói uma árvore DOM. Até que você habilite o motor de script, quaisquer blocos ` + + +``` + +Убедитесь, что файл находится в месте, доступном вашему Java‑процессу — `YOUR_DIRECTORY/script_demo.html` в коде ниже. + +--- + +## Шаг 1: Загрузка HTML‑документа в Java + +Первое, что вам нужно, — экземпляр `HTMLDocument`, указывающий на ваш файл. Конструктор Aspose.HTML может принимать объект `ScriptEngineOptions`, который даёт контроль над средой выполнения скриптов. + +```java +import com.aspose.html.HTMLDocument; +import com.aspose.html.scripting.ScriptEngineOptions; + +public class JsEngineDemo { + public static void main(String[] args) throws Exception { + + // Load the HTML file – this also prepares the DOM for script execution + HTMLDocument htmlDoc = new HTMLDocument("YOUR_DIRECTORY/script_demo.html"); + // ... we’ll configure the engine in the next step + } +} +``` + +**Почему это важно:** загрузка документа парсит разметку и строит дерево DOM. Пока вы не включите движок скриптов, любые блоки ` + + +``` + +Asegúrate de que el archivo esté en una ubicación que tu proceso Java pueda leer—`YOUR_DIRECTORY/script_demo.html` en el código a continuación. + +--- + +## Paso 1: Cargar documento HTML en Java + +Lo primero que necesitas es una instancia de `HTMLDocument` que apunte a tu archivo. El constructor de Aspose.HTML puede aceptar un objeto `ScriptEngineOptions`, que te brinda control sobre el entorno de scripting. + +```java +import com.aspose.html.HTMLDocument; +import com.aspose.html.scripting.ScriptEngineOptions; + +public class JsEngineDemo { + public static void main(String[] args) throws Exception { + + // Load the HTML file – this also prepares the DOM for script execution + HTMLDocument htmlDoc = new HTMLDocument("YOUR_DIRECTORY/script_demo.html"); + // ... we’ll configure the engine in the next step + } +} +``` + +**Por qué es importante:** Cargar el documento analiza el marcado y construye un árbol DOM. Hasta que habilites el motor de scripts, cualquier bloque ` + + +``` + +Se till att filen finns någonstans där din Java‑process kan läsa den—`YOUR_DIRECTORY/script_demo.html` i koden nedan. + +--- + +## Steg 1: Ladda HTML‑dokument i Java + +Det första du behöver är en `HTMLDocument`‑instans som pekar på din fil. Aspose.HTML:s konstruktor kan ta emot ett `ScriptEngineOptions`‑objekt, vilket ger dig kontroll över skriptmiljön. + +```java +import com.aspose.html.HTMLDocument; +import com.aspose.html.scripting.ScriptEngineOptions; + +public class JsEngineDemo { + public static void main(String[] args) throws Exception { + + // Load the HTML file – this also prepares the DOM for script execution + HTMLDocument htmlDoc = new HTMLDocument("YOUR_DIRECTORY/script_demo.html"); + // ... we’ll configure the engine in the next step + } +} +``` + +**Varför detta är viktigt:** Att ladda dokumentet parsar markupen och bygger ett DOM‑träd. Tills du aktiverar skriptmotorn ignoreras alla ` + + +``` + +ตรวจสอบให้แน่ใจว่าไฟล์อยู่ในตำแหน่งที่โปรเซส Java ของคุณสามารถอ่านได้—`YOUR_DIRECTORY/script_demo.html` ในโค้ดด้านล่าง + +--- + +## ขั้นตอนที่ 1: โหลดเอกสาร HTML ใน Java + +สิ่งแรกที่คุณต้องมีคืออินสแตนซ์ `HTMLDocument` ที่ชี้ไปยังไฟล์ของคุณ ตัวสร้างของ Aspose.HTML สามารถรับอ็อบเจกต์ `ScriptEngineOptions` ซึ่งให้คุณควบคุมสภาพแวดล้อมการสคริปต์ + +```java +import com.aspose.html.HTMLDocument; +import com.aspose.html.scripting.ScriptEngineOptions; + +public class JsEngineDemo { + public static void main(String[] args) throws Exception { + + // Load the HTML file – this also prepares the DOM for script execution + HTMLDocument htmlDoc = new HTMLDocument("YOUR_DIRECTORY/script_demo.html"); + // ... we’ll configure the engine in the next step + } +} +``` + +**ทำไมเรื่องนี้ถึงสำคัญ:** การโหลดเอกสารจะทำการพาร์ส markup และสร้างต้นไม้ DOM จนกว่าคุณจะเปิดใช้งานเครื่องยนต์สคริปต์, ` + + +``` + +Dosyanın Java sürecinizin okuyabileceği bir konumda olduğundan emin olun—aşağıdaki kodda `YOUR_DIRECTORY/script_demo.html`. + +--- + +## Adım 1: Java’da HTML Belgesi Yükleme + +İlk olarak dosyanıza işaret eden bir `HTMLDocument` örneğine ihtiyacınız var. Aspose.HTML’in yapıcı metodu bir `ScriptEngineOptions` nesnesi alabilir; bu da betik ortamı üzerinde kontrol sağlar. + +```java +import com.aspose.html.HTMLDocument; +import com.aspose.html.scripting.ScriptEngineOptions; + +public class JsEngineDemo { + public static void main(String[] args) throws Exception { + + // Load the HTML file – this also prepares the DOM for script execution + HTMLDocument htmlDoc = new HTMLDocument("YOUR_DIRECTORY/script_demo.html"); + // ... we’ll configure the engine in the next step + } +} +``` + +**Neden önemli:** Belgeyi yüklemek, işaretlemi ayrıştırır ve bir DOM ağacı oluşturur. Betik motorunu etkinleştirene kadar ` + + +``` + +Đảm bảo tệp nằm ở vị trí mà tiến trình Java của bạn có thể đọc—`YOUR_DIRECTORY/script_demo.html` trong mã dưới đây. + +--- + +## Bước 1: Tải tài liệu HTML trong Java + +Điều đầu tiên bạn cần là một thể hiện `HTMLDocument` trỏ tới tệp của bạn. Constructor của Aspose.HTML có thể nhận một đối tượng `ScriptEngineOptions`, cho phép bạn kiểm soát môi trường script. + +```java +import com.aspose.html.HTMLDocument; +import com.aspose.html.scripting.ScriptEngineOptions; + +public class JsEngineDemo { + public static void main(String[] args) throws Exception { + + // Load the HTML file – this also prepares the DOM for script execution + HTMLDocument htmlDoc = new HTMLDocument("YOUR_DIRECTORY/script_demo.html"); + // ... we’ll configure the engine in the next step + } +} +``` + +**Tại sao điều này quan trọng:** Việc tải tài liệu sẽ phân tích markup và xây dựng cây DOM. Cho đến khi bạn bật engine script, bất kỳ khối `