Getting Started
Contents
Getting Started#
Using JavaScript Objects And Libraries#
Just like in the JavaScript, all global JavaScript objects, functions, and variables can be accessed through the window
object.
from browser import window
window.alert("Hello World!")
window.console.log("Hello World!")
Using Javascript Constructors#
Since Python doesn’t have new
keyword, JavaScript classes can be initialized
by the new
special method added automatically to the JavaScript objects.
from browser import window
new_date = window.Date.new()
print(new_date)
Accessing HTML Elements#
DOM api can be used as same as on the JavaScript via document
object.
from browser import document
title = document.createElement("div")
title.id = "my_title"
title.innerHTML = '<b>Pysketch</b> is an online <a href="http://www.python.org">Python</a> editor for web browsers.</body>'
document.body.appendChild(title)
print(document.getElementById("my_title"))