Skip to content

Commit 9712bae

Browse files
Enable JS features for WebView lesson
1 parent de04873 commit 9712bae

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

app/src/main/java/com/d4rk/androidtutorials/java/ui/screens/android/lessons/views/web/WebViewActivity.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ private void setupWebView() {
3939
webView.loadUrl("https://d4rk7355608.github.io/profile/#home");
4040
WebSettings webSettings = webView.getSettings();
4141
webSettings.setJavaScriptEnabled(true);
42+
webSettings.setDomStorageEnabled(true);
43+
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
4244
}
4345

4446
private void setupFloatingButton() {

app/src/main/res/raw/text_webview_java.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Import the necessary classes and libraries
22
import android.content.Intent;
33
import android.os.Bundle;
4+
import android.webkit.WebSettings;
45
import androidx.appcompat.app.AppCompatActivity;
56

67
// This class extends AppCompatActivity and represents the main activity of an Android app
@@ -19,6 +20,10 @@ public class MainActivity extends AppCompatActivity {
1920
setContentView(binding.getRoot());
2021

2122
// Load a URL in the web view in the layout
23+
WebSettings webSettings = binding.webView.getSettings();
24+
webSettings.setJavaScriptEnabled(true);
25+
webSettings.setDomStorageEnabled(true);
26+
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
2227
binding.webView.loadUrl("https://d4rk7355608.github.io/profile/#home");
2328
}
2429
}

0 commit comments

Comments
 (0)