How to embed JavaScript code in an HTML page. JavaScript: Hiding the script from prying eyes JavaScript: Hiding the script from prying eyes

It’s very simple - just right-click on it and select the appropriate item in the context menu. The wording may vary depending on the browser you are using: in Mozilla Firefox it is called "Source", in Apple Safari - "View source", in Google Chrome - "View page code", in Opera - "Source code", in Internet Explorer - " View HTML code."

The source code of server scripts that generate the HTML code of the page with normally configured server software cannot be obtained with a simple request. You can view the source code of PHP or Perl scripts only by downloading their files via FTP protocol or through the file manager of the hosting control panel or site management system. You can open such files with a regular text editor.

The source code of client-side scripts that execute directly in the browser (for example, JavaScript) can be viewed by extracting their files from the browser cache. And it’s even easier to save pages with all the accompanying files to a specific location. In this case, you won’t have to dig through everything stored in the cache. To do this, in any browser you need to press the key combination CTRL + S, and then in the “File type” field select “Full web page”. You can also open files with the js extension containing the source code of the script using a regular text editor.

The source code of Flash movies that are downloaded by a browser to your computer is not so easy to view. The browser does not receive the source code, but only its compiled version - the executable code. However, there are decompiler programs that can perform the reverse conversion procedure. For example, Trillix's Flash Decompiler is built into your browser and allows you to extract a Flash object from a page and save it. By then opening the flash in the decompiler, you will have access to its individual components - images, scripts, sounds, etc. Of course, this code will not fully correspond to the author’s source code, but only with a degree of accuracy sufficient for operation.

“Source code” most often refers to the code of a program in a human-readable (high-level) programming language. Having this code, you can make changes to the program (script, flash movie, java application, application program, etc.). The author or distributor of the program determines whether to distribute the source code along with the finished product. There is a whole class of applications that are distributed “open source”; the source code of other programs (for example, JavaScript scripts or HTML pages) by definition cannot be hidden, and the source code of other programs is subject to copyright.

Instructions

Get the open source source code of the application on the website of the author or distributor of this software product. You can usually find out the website address in the menu section called “Help” if you select the “About the program” item in it.

Right-click a web page if you want to access its source code. In any browser, the pop-up context menu will contain a command to view the source, although the wording may vary slightly. You can do without the context menu - the key combination ctrl + u duplicates the call to the source view command. Some browsers have built-in viewing tools (Mozilla Firefox, Google Chrome), others use external programs for this - most often Notepad. You can save the page source obtained in this way to a file.

We've released a new book, Social Media Content Marketing: How to Get Inside Your Followers' Heads and Make Them Fall in Love with Your Brand.

The source code of a site is a collection of HTML markup, CSS styles and JavaScript scripts that the browser receives from the web server.

More videos on our channel - learn internet marketing with SEMANTICA

It can be compared to a set of commands given to soldiers by a commander. Imagine that the audience does not see or hear the boss. From their point of view, the military carries out actions independently. In our case, the commander is the browser, the commands are the source code, and the marching soldiers are the final result.

The site is stored on a web server, which sends the page upon user request. A request is typing a URL in the address bar, clicking a link, or clicking a submit button on a form. It doesn’t matter what language the web pages are written in or whether they include a software component. The end result of any server-side algorithm is a set of html tags and text.
The page source code is a set of data that includes:

  • html markup;
  • style sheet or file link;
  • programs written in JavaScript or links to files with code.

These three sections are processed by the browser. For the server, this is simply the text that needs to be sent in response to the request.

Why we might need to study the source code

Everything we see, we can analyze and apply to solve certain problems that arise while working with the site, especially when optimizing it. By looking at the source code, we can:

  • See the meta tags of your or someone else’s site to analyze them.
  • See the presence or absence of certain elements on the site: counters, identification codes in various systems, certain scripts and other things.
  • Find out the parameters of the elements: sizes, colors, fonts.
  • Find the path to photos and other elements located on the page.
  • Explore links from the page.
  • Find problems with the code that interfere with the process of site optimization: styles not placed in separate files, scripts, invalid code.

These are the basic features, but in fact, by being able to read the code, you can learn a lot more about the page.

How to view the source code of a site

It will not be possible to do this completely in the form in which it is posted on the server from the browser. But you can see all the markup by right-clicking on the page. Here and below using Google Chrome as an example.

Select the “View page code” option and get the full listing in a separate tab.

It's just text that you have to analyze to understand. But you can get interactive code using the developer tools.

How to find the source code of a website page

Click on the menu icon in the browser. Most often it is on the right and looks like three dots or stripes.

In the additional tools section, select “Developer Tools”.

A window will open showing the active state of the code. This means that when you click on the markup, the element style will appear next to it, and the selected blocks will be highlighted on the page.

In the “Source” tab you can view the contents of some files: scripts, fonts, images.

In the “Security” tab, you can check the site’s certificate.

The “Audits” tab will help you check the resource posted on the hosting.

If the location of the panel on the right is inconvenient, you can click the three dots and change it by selecting the desired item.

How to view meta tags

Every HTML document includes structure tags. Here are some of them:

  • Html – the entire document.
  • Head – section of service headers.
  • Title – page title (displayed on the tab).
  • Body – the body of the document.
  • H1-H6 – page text headings.
  • Article – article.
  • Section - section.
  • Menu – menu.
  • Div – block.
  • Span – string.
  • P – paragraph.
  • Table – table.
  • Elements are designed to logically delimit sections on a page; if necessary, they are designed using styles. They contain text that is somehow visible on the page. But the Head tag contains service information. Meta tags are used to indicate it. Everything that is written in them is intended for the server and search engines.

    Their contents cannot be found out in any other way.

    Let's pay attention to the Link tag. With its help, links to external included files are specified. If desired, you can see the contents and save to disk. To do this, move the pointer to the address and press RMB. Select "Open in new Tab".

    The specified file will open in a new tab, which you can view or save.

    How to view the source code of a page to debug a script

    In this case, it is most convenient to open the page on the local machine. If you only need to correct markup, styles and scripts, then this can be done directly from the folder. The HTML code is viewed in the same way. But JavaScript code errors can be seen in the “Console” tab. This shows the description of the error and the line number where it occurred.

    The syntax can be seen directly in the code. This is what the “Source” tab is for.

    How to view the code of a specific element

    For large pages with many elements, it is difficult to find the necessary code in all the markup. In this case, you should use a special context menu command. Move the mouse over the fragment and press RMB. Select the “View Code” command.

    The same window will open, but with the focus on the selected object.

    Summary

    We told you what the page source code is. It is enough to master basic knowledge of HTML and CSS, and using convenient developer tools, you will be able to debug your own HTML documents.

    Reviewing the code of resources on the Internet will allow you to learn not only from your own experience, but also to use real working examples. And for SEO specialists, meta tags will be useful, the information in which can tell a lot about the site.

    Have you ever wanted to hide a script on your page from strangers that makes an unrealistically beautiful menu appear or perform other actions that you would not want to see on every second website soon?
    If yes, then the method outlined in this article will be useful to you along with code obfuscation. At the same time, I’ll make a reservation right away that the method is not 100 percent effective, but it will probably protect you from most non-professionals and some professionals.

    Theory Let's say we have a page nojs.php, and on it a secret.js script that needs to be hidden. The browser and the user can receive the script from the server in the following ways:
  • Loading a script directly placed on the page or loaded using the DOM;
  • View the script in the Page Source Code window;
  • Saving a page with all files to your hard drive;
  • Entering a direct URL in the address bar.
  • In the first case, the browser must send the HTTP_REFERER HTTP header.
    In the second and third cases, it is not transmitted by all browsers (Chrome, FireFox display a previously downloaded script from the cache; Opera, IE download the script again, but without sending the referer).
    In the fourth case, the referer is not transmitted by any of the four browsers.
    If we issue JavaScript dynamically and check for the presence of the referer header in the request, then we will immediately protect ourselves from Opera and IE, but for Crome and Firefox we will have to come up with something trickier. We will first download one script, which in turn will download another script, and both downloads will be checked for the presence of an http-referer. It has been scientifically established that if you dynamically create a script on the page document.createElement("script"), and then delete it from the page, the script will work as usual, but it will not be saved. Practicenojs.php This page has a purpose load script1.php
    Find JS After 10 seconds you should see the hidden script working in the form of an alert, click the link after the alert to make sure that the events have not fallen off either. At this link you can see the hidden script script1.php Its task: dynamically load script2.php if there is a referer header. Timeouts can be reduced, depending on the approximate execution time of the hidden script.
    script2.php Its task is to produce the final script if there is a referer header
    Results As a result, we get that we can neither look at the source code of the page, nor download or save the hidden script using the four browsers tested. In general, you can watch it in two ways:
    • Follow the link directly leading to script2.php and located on the page of our website;
    • Formation of an http request indicating the referer header.
    You can increase the effectiveness of hiding using the following methods:
  • Using mod-rewrite, replace the script1.js and script2.js going to the server with script1.php and script2.php, respectively, so that the page contains the familiar js files, since php is striking;
  • Make the fictitious script as complex, plausible and confusing as possible, so that the person trying to parse it will suffer greatly before realizing that he was deceived;
  • Code obfuscation.
  • Disclaimer!

    What you will see inside the source is terrible shit code, which it is advisable not to use in your projects in order to avoid all the problems that I myself once encountered. If you, of course, being an immortal person, decide to use my code in your projects, then I warn you that I decline all responsibility for its use and any problems you may encounter. When posting your various modifications, if any, change their name, because Police Tools still exists and is supported by the developer. It is recommended to take such things seriously, because no one is safe from Takedown, and I intend to protect the copyright on my product until the end of support for this script. The issue of copyright applies not only to publication on BlastHack, but on all sites in general . Thanks for understanding!

    Happy exploring!

    Have a good day, gentlemen LUA people. Today, January 1, 2019, I would like to present you with the full source code of my script Police Tools. So that people do not run to create their own copies of my brainchild, I will say that this version is old enough that its systems no longer pose a danger to my main project. I’ll say right away that I’m posting this project here because... I want to help people who want to know LUA to learn. It’s not stupid to copy the code, change the name and pass off the project as your own, but to gain knowledge. I, like no one else, understand what it’s like to start completely from scratch, without having a more or less good example at hand. I will also not say that this project is wonderful. I started writing it in 2017, then I myself was just starting to do scripting on LUA, there can be terrible systems.

    A huge part of the code is commented out, you don’t even have to look at it, I was too lazy to cut it out.


    I recommend reading this topic in its entirety, otherwise you will most likely not understand anything when you open the source code. Ready to read? I hope your answer is positive. Let's start. ​


    The source itself consists of some things that are very difficult for beginners to master:


    ImGUI windows and overlays [main interface]
    Working with the network [asynchronous requests / regular HTTP requests]
    Working with INI configs [script settings]
    Working with multi-step dialogs [additional interface]
    Working with regular expressions [lua pattern]
    A little work with SAMP LUA.


    Now let's discuss the problematic parts of my source code:


    Very confusing code because... I wrote it for almost three years, God bless it.
    Lots of comments that essentially don’t make any sense and were just notes.
    In some places there is a huge number of lines instead of one possible, but this is not critical.


    If we talk about the advantages, we can highlight the following:

    10k clean code + another 3k sometimes useful comments.
    Private systems for which I once paid my hard-earned money.
    High-quality systems that can serve as sources for network functions.


    I’ll also simplify your task and list interesting functions:

    Automatic roleplaying of weapons.

    Can be found in main, comment [ WEAPON_FUNCTION_BEGIN ]. ​

    Slightly redesigned system of cyclic asynchronous requests.

    Can be found via search, function [loop_async_http_request]. ​

    A full-fledged in-script chat system with functions above.

    Can be found on line [3985] or by key. word [getmsg2.php]. ​

    A full-fledged database of the Ministry of Internal Affairs will do as an example.

    Can be found on line [8124] or by key. word [cmd_database]. ​

    A full-fledged in-script binder system with tags.

    Mini MVDHelper, as many believe, can be found throughout the script.


    This source code uses the following libraries:

    Samp.lua
    dear imgui
    memory
    encoding [ for ImGUI, respectively ] ​



    Perhaps I will add useful and interesting information to this topic. You understand, the night after the New Year is always difficult. If I forgot to add something, and you found it in the source, then write in the topic, I will be very grateful to you. I hope that with my source code I can help at least some of those who are starting to learn LUA, or are trying to write their first script. If you have questions about the source, you can also ask them in this topic. If you want to leave a review, please go ahead, the whole topic is at your disposal. And let me remind you once again that I started writing this script when I was just studying, so you shouldn’t criticize it too much. We are all human, we all make mistakes one way or another. A huge request, create unique scripts, do not repeat after others, unless, of course, you learn from someone else's example. Remember, if something doesn’t work out for you, try further - someday you will definitely succeed if you don’t give up. Don't try to hide your code, let people see what you can do. After all, this is the only way they will be able to recognize you as a person who can write code and is not afraid to show it. I understand that I am far from the first to publish a huge project, but I also hope that I am not the last to do so. Well, Pavel Garson was in touch with you, study and achieve everything you want. And yes, I provide this source for review, and not for blatant copying. If you copy it, write where you got it. And thank you, everyone.


    Actually, I think that you absolutely don’t care what I wrote above, you’re just looking for the source.
    Huge respect to those people who read the entire text that I came up with after New Year =))

    Natasha October 31, 2011 at 03:10 JavaScript: Hiding the script from prying eyes
    • Lumber room *

    Have you ever wanted to hide a script on your page from strangers that makes an unrealistically beautiful menu appear or perform other actions that you would not want to see on every second website soon?
    If yes, then the method outlined in this article will be useful to you along with code obfuscation. At the same time, I’ll make a reservation right away that the method is not 100 percent effective, but it will probably protect you from most non-professionals and some professionals.

    Theory Let's say we have a page nojs.php, and on it a secret.js script that needs to be hidden. The browser and the user can receive the script from the server in the following ways:
  • Loading a script directly placed on the page or loaded using the DOM;
  • View the script in the Page Source Code window;
  • Saving a page with all files to your hard drive;
  • Entering a direct URL in the address bar.
  • In the first case, the browser must send the HTTP_REFERER HTTP header.
    In the second and third cases, it is not transmitted by all browsers (Chrome, FireFox display a previously downloaded script from the cache; Opera, IE download the script again, but without sending the referer).
    In the fourth case, the referer is not transmitted by any of the four browsers.
    If we issue JavaScript dynamically and check for the presence of the referer header in the request, then we will immediately protect ourselves from Opera and IE, but for Crome and Firefox we will have to come up with something trickier. We will first download one script, which in turn will download another script, and both downloads will be checked for the presence of an http-referer. It has been scientifically established that if you dynamically create a script on the page document.createElement("script"), and then delete it from the page, the script will work as usual, but it will not be saved. Practicenojs.php This page has a purpose load script1.php
    Find JS After 10 seconds you should see the hidden script working in the form of an alert, click the link after the alert to make sure that the events have not fallen off either. At this link you can see the hidden script script1.php Its task: dynamically load script2.php if there is a referer header. Timeouts can be reduced, depending on the approximate execution time of the hidden script.
    script2.php Its task is to produce the final script if there is a referer header
    Results As a result, we get that we can neither look at the source code of the page, nor download or save the hidden script using the four browsers tested. In general, you can watch it in two ways:
    • Follow the link directly leading to script2.php and located on the page of our website;
    • Formation of an http request indicating the referer header.
    You can increase the effectiveness of hiding using the following methods:
  • Using mod-rewrite, replace the script1.js and script2.js going to the server with script1.php and script2.php, respectively, so that the page contains the familiar js files, since php is striking;
  • Make the fictitious script as complex, plausible and confusing as possible, so that the person trying to parse it will suffer greatly before realizing that he was deceived;
  • Code obfuscation.