Hello Koders!
In this guide, I’ll show you how to encode text to Base64 in Kodular using WebViewer and JavaScript, without needing any external extension.
This method is fast, clean, and works offline.
What is Base64?
Base64 is a method for converting text (or binary data) into a string format made up of only letters, numbers, +
, /
, and =
. It’s commonly used in:
- Encoding images for HTML
- Sending data over APIs
- Obfuscating strings (like API keys)
Why Use WebViewer?
Kodular does not have a built-in Base64 encoder. But we can use the WebViewer’s EvaluateJavaScript
block to run JavaScript code and use the built-in btoa()
function.
How to Do It (Step by Step)
Step 1: Add Components
From the Palette, add the following to your screen:
- WebViewer (Rename to
WebViewer1
)- Set
Visible = false
- Enable
Allow JavaScript = true
- Set
- Textbox (to enter text you want to encode)
- Button (to trigger encoding)
- Label (to show the Base64 result)
Step 2: Use Blocks
Now go to the Blocks section and add the following logic:
When Button.Click
call WebViewer1.EvaluateJavaScript
with text: "btoa('TextBox1.Text')"
This runs the JavaScript function
btoa()
to encode the input text. Alsoatob()
to decode the input text
When WebViewer1.AfterJSEvaluated
set Label1.Text to get value
This takes the result from JavaScript and shows it in the Label.
Example
- Input:
Hello Kodular
- Output (Base64):
SGVsbG8gS29kdWxhcg==
Important Notes
btoa()
works best with ASCII characters.- If you want to encode non-English or UTF-8 text (like
नमस्ते
,你好
), you’ll need an advanced Base64 encoder (possibly via extension or custom HTML page).
- If you want to encode non-English or UTF-8 text (like
- You can also use
atob()
to decode Base64 back to normal text using the same method.
That’s It!
You’ve now created a simple Base64 encoder in Kodular without any external extension. You can use this for encoding API keys, converting images, or even for fun.
If you found this helpful, leave a or reply below with suggestions and questions. Happy Koding!