Page 53 - JavaScript
P. 53
Using SVG
SVG is for building scalable vector-based graphics and can be used within HTML.
First create an SVG element container with dimensions:
var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
svg.width = 500;
svg.height = 50;
Then build a text element with the desired positioning and font characteristics:
var text = document.createElementNS('http://www.w3.org/2000/svg', 'text');
text.setAttribute('x', '0');
text.setAttribute('y', '50');
text.style.fontFamily = 'Times New Roman';
text.style.fontSize = '50';
Then add the actual text to display to the textelement:
text.textContent = 'Hello world!';
Finally add the text element to our svg container and add the svg container element to the HTML
document:
svg.appendChild(text);
document.body.appendChild(svg);
Image file
If you already have an image file containing the desired text and have it placed on a server, you
can add the URL of the image and then add the image to the document as follows:
var img = new Image();
img.src = 'https://i.ytimg.com/vi/zecueq-mo4M/maxresdefault.jpg';
document.body.appendChild(img);
Using window.confirm()
The window.confirm() method displays a modal dialog with an optional message and two buttons,
OK and Cancel.
Now, let's take the following example:
result = window.confirm(message);
Here, message is the optional string to be displayed in the dialog and result is a boolean value
indicating whether OK or Cancel was selected (true means OK).
window.confirm() is typically used to ask for user confirmation before doing a dangerous operation
https://riptutorial.com/ 10

