Writing scripts Archives - PAGE2STAGE https://www.page2stage.com What is a script and scripting language Wed, 27 Apr 2022 15:30:45 +0000 en-US hourly 1 https://wordpress.org/?v=5.9.3 https://www.page2stage.com/wp-content/uploads/2022/04/cropped-logo-32x32.jpg Writing scripts Archives - PAGE2STAGE https://www.page2stage.com 32 32 How to write JavaScript https://www.page2stage.com/how-to-write-javascript/ Wed, 27 Apr 2022 15:30:43 +0000 https://www.page2stage.com/?p=89 For example, let's make a simple script to be executed by the Windows Script Server. This script can be written directly in Notepad and executed without a browser.

The post How to write JavaScript appeared first on PAGE2STAGE.

]]>
For example, let’s make a simple script to be executed by the Windows Script Server. This script can be written directly in Notepad and executed without a browser.

WScript.echo (“Hello Skillbox!”)

We write this text in Notepad, then save the file under the name skillbox.js and run it in Windows Explorer.

A similar script can be written directly in the HTML page code between the tags. You can already use normal JavaScript methods there, rather than the echo method of a specific WScript object. Let’s look at some of the standard methods for input and output in a browser.

alert()
The alert() method displays a window with an OK button. A message is displayed in the window, which is indicated in brackets. For example, “Hi, Skillbox!”. That is, in this case, the browser does exactly the same thing that the Windows Script Server did before.

These examples can also be written in Notepad, but saved as files with the HTML extension. For example, skillbox.htm.

As an argument to alert(), you can specify not only a specific text, but also the result of any calculations or processing of other data. For example, alert(x), where x is calculated separately.

confirm()
The confirm() method displays the same message box, but with two buttons – “OK” and “Cancel”. Depending on which button the user clicks, the method returns either true or false. The server receives this return value from the user and performs some action based on the response.

The syntax is the same, only a choice is logically assumed here, so the user is asked a question.

prompt()
The prompt() method displays a dialog box with a message and a text field where the user enters data. There are also two buttons “OK” and “Cancel”. On pressing the first button, the method returns the entered text to the server, and on pressing the second button, it returns the boolean value false.

The syntax here is:
prompt(message, input_field_value)

The input field value is optional. There you can enter the text that was originally entered in the field for the convenience of the user.

The code:

The possibilities of modern JavaScript go far beyond the primitive input / output of data through forms. We have given these methods only as the simplest examples. In addition, JavaScript allows you to respond to user actions. For example, on mouse movements or pressing certain keys. JavaScript is often used to provide asynchronous work (AJAX technology), where information on the page is updated without reloading it. In this mode, data is sent to the server and downloaded from there interactively. In addition, JavaScript is capable of manipulating HTML elements on a page (creating and hiding tags, etc.) and much more.

Useful Tools

Developer Console
All popular browsers have a dedicated developer console. It shows the script code on the page and also displays other useful information. In Chrome, Firefox and IE, the developer console is opened by pressing the F12 hotkey, in Safari – Ctrl+Shift+I or Ctrl+Alt+C. In the screenshot, the scripts are displayed at the top right, along with other elements of the web page.

Code editors
In the future, for convenient programming, you will need to install a code editor or IDE (Integrated Development Environment), an integrated development environment. An IDE is an editor with extended functionality that is integrated with other useful tools, supports connecting additional modules, and so on.

The post How to write JavaScript appeared first on PAGE2STAGE.

]]>
WEB applications and gadgets for Google sites https://www.page2stage.com/web-applications-and-gadgets-for-google-sites/ Wed, 27 Apr 2022 15:23:21 +0000 https://www.page2stage.com/?p=86 Standalone and embedded scripts can be web applications if the following requirements are met

The post WEB applications and gadgets for Google sites appeared first on PAGE2STAGE.

]]>
Requirements for a web application
Standalone and embedded scripts can be web applications if the following requirements are met:

  • The script contains a doGet(e) or doPost(e) function
  • the function returns an HTML service object HtmlOutput or Content service TextOutput
  • Deploying a script as a Web application

To publish a script as a web application, you must:

  • Write a new version of the script by selecting File > Manage Versions and clicking Save New Version.
  • Publish the script by choosing Publish > Deploy as web app.
  • In the Project version field select the version you have recorded.

Under Execute the app as select the type of authorization: the developer’s account or the user running the script.

Under Who has access to the app specify who has the right to run the application. The options depend on the type of your account, but usually contain the following fields: “Only myself” – only me; any member of your domain – any member of your domain, “Anyone” (with a Google account) – anyone with a Google account; “Anyone, even anonymous” – anyone, even anonymous.

Click on Deploy.

This will open a dialog with a message saying that the project has been deployed as a web application. This message contains two important URLs for your application:

The first is called the Current web app URL and ends in /exec. This is the URL of the published version of the deployed application, based on the latest entry.

The second is called latest code and ends in /dev. This link is only available to users with permission to edit the script. This instance of the application always runs the last recorded version of the script regardless of the formal version – and is intended for quick testing during development.

You can share a link to your app with anyone who wants to run it. You can also publish the app to the Chrome Web Store for public use.

Including a web app in the Google Site
Web apps can be included in the Google Site (sometimes called site gadgets).

To create a script linked to the Google Site you need to:

  • Go to the site
  • Click on the gear icon (right top corner of the screen).
  • Select Manage site
  • Click on Google Apps Scripts, and then on Add new script

After this, the process is similar to the one presented in the “Deploying the script as a Web application” section.

To connect a web app to the Google Site you need to:

  • Enter the site
  • Go to the page to which the application will be connected
  • Click the pencil icon (editing mode)
  • Select Insert > Google Apps Script in the menu
  • Select the application from the list.
  • Click on Select and then Save.
  • Save the changes on the page and exit edit mode

URL options
When the user launches the app or the app receives an HTTP GET request, Apps Script runs the doGet(e) function. When the application receives an HTTP POST request Apps Script runs the doPost(e) function. In both cases, the argument e is an event parameter that contains information about the URL parameters.

For example you can pass parameters along with the URL, in this case the user’s name and age:

https://script.google.com/…/exec?username=jsmith&age=21

You can then display the parameters as follows:

function doGet(e) {
var params = JSON.stringify(e);
return HtmlService.createHtmlOutput(params);
}

In the previous example, doGet(e) returns the following object:

{
“queryString”: “username=jsmith&age=21”,
“parameter”: {
“username”: “jsmith”,
“age”: “21”
},
“contextPath”: “”,
“parameters”: {
“username”: [
“jsmith”
],
“age”: [
“21”
]
},
“contentLength”: -1
}

Credentials
The credentials of a web application depend on who runs it, the owner of the application or the user who visited the page on the site where it is located.

The post WEB applications and gadgets for Google sites appeared first on PAGE2STAGE.

]]>
Is it difficult to write scripts yourself? https://www.page2stage.com/to-write-scripts-yourself/ Wed, 27 Apr 2022 15:14:57 +0000 https://www.page2stage.com/?p=83 Writing scripts requires knowledge of a specific programming language and general principles:

The post Is it difficult to write scripts yourself? appeared first on PAGE2STAGE.

]]>
Writing scripts requires knowledge of a specific programming language and general principles:

  • use of variables;
  • loops;
  • working with strings.

An ordinary hosting user does not need to learn how to write scripts on his own. This skill may be required if one decides to engage in programming professionally.

If you just need to add interactivity to your site, you can use ready-made scripts in JavaScript.

Users of virtual hosting also need to study the instructions on the use of scripts, for example, to properly configure their execution on a schedule. The instructions will specify in what place of a particular file to place the text of the script.

The easiest variant is the Shell scripts, which are a set of Linux commands executed one by one, but even in this case, you should understand the meaning of a particular command and present the results of its execution.

For example, a simple script can be created and run directly from the command line in the console.

It is enough to just type

pwd ; whoami.

And then finish the commands by pressing Enter.
This line contains two commands separated by semicolons.

pwd – (present working directory) command prints the directory you are currently in.
whoami – the command prints the user name (login).

The Shell interpreter will execute the commands one by one and the result will appear on the screen.

The post Is it difficult to write scripts yourself? appeared first on PAGE2STAGE.

]]>
How do I write a script for the browser? https://www.page2stage.com/script-for-the-browser/ Wed, 27 Apr 2022 15:09:53 +0000 https://www.page2stage.com/?p=79 Today, working with information is quite common, even for those who are not directly involved in journalism.

The post How do I write a script for the browser? appeared first on PAGE2STAGE.

]]>
Today, working with information is quite common, even for those who are not directly involved in journalism. We are talking about the fact that today everyone regularly uses the Internet to obtain relevant information on a particular query.

However, this work is not always done in an efficient way. Of course, the optimization and automation of working with information in the browser, primarily concerns professionals.

Meanwhile, useful aspects of the aforementioned processes can also be recommended for ordinary users. As far as they can be applied without any special knowledge. The Human Emulator program allows you to write your own scripts to work in your browser.

Why write scripts: What’s in it for you?
A script is program code that allows you to automate an action that is regularly repeated. Essentially, a script will perform an action exactly as if it were performed by a human being in person.

However, until recently, solving the above problem was the sole prerogative of professional programmers. Today, however, there is software on the market (free, by the way), which allows you to do the same thing, but without knowledge of the programming language.

The advantages of automating work in the browser are obvious:

  • increased speed of working with information;
  • reducing the number of errors;
  • providing high positive results in work.

The fact is that any work with information has a kind of patterns. Regardless of the focus of the information, these patterns are repeated. They allow collecting, accumulating, systematizing and processing massive amounts of information in the most effective way.

Automation – the path to success
Analyzing a large amount of information always leads to significant losses of time. But the main problem is still the errors. A human is a human being, of course.

The human factor cannot be excluded in information processing and analysis. A script is a program code which executes a fixed order of operations without errors.

Let’s note that for the solution of complex tasks it will still be necessary to know the basics of programming language.

How to write a script to do your own testing with PHP?
In this article it will be about realization of simple testing by means of PHP.

It is necessary to note at once that choosing PHP, instead of javascript you receive greater reliability in testing, as PHP is a server programming language and it is executed on the server, it is much more difficult to peep answers and the code itself, than it is with javascript.

In the quiz we will have different questions, with different choices of answers – selecting one answer from a group, writing the answer to a textbox, choosing several answers in an answer.

The post How do I write a script for the browser? appeared first on PAGE2STAGE.

]]>