Applications of Javascript Frameworks & Protect Web Page Css
Applications of Javascript Frameworks & Protect Web Page Css
Kautkar
Unit No. 6
1) React:
2) Angular:
3) Vue.js:
4) Ember.js:
5) Backbone.js:
It's important to understand that while you can take some measures to protect
your webpage in JavaScript, none of them can provide absolute security. A
determined attacker can often find ways to bypass these protections. However, the
following are some techniques you can use to enhance the security of your
webpage:
You can hide your JavaScript from a visitor by storing it in an external file on your
web server. The external file should have the .js file extension. The browser then
calls the external file whenever the browser encounters a JavaScript element in the
web page. If you look at the source code for the web page, you'll see reference to
the external .js fi le, but you won't see the source code for the JavaScript.
The next example shows how to create and use an external JavaScript file. First you
must tell the browser that the content of the JavaScript is located in an external file
on the web server rather than built into the web page. You do this by assigning the
file name that contains the JavaScripts to the src attribute of the <script> tag.
Example:
<html>
<head>
</head>
<body>
<h1>Hello, World!</h1>
<script src="script.js"></script>
</body>
</html>
Create a separate JavaScript file (e.g., script.js) with your JavaScript code. For
example:
// script.js
One way to protect your JavaScript source code is through minification and
obfuscation. Minification reduces your code's readability by removing whitespace
and shortening variable names, making it harder for others to understand.
You can attempt to prevent users from right-clicking on your webpage, which is often
done to access the context menu and view the page source. However, this method is
easily bypassed by determined users.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script type="text/javascript">
});
</script>
</body>
</html>
In the code above, we're using the contextmenu event and preventing its default
action using the e.preventDefault() method. This will stop the context menu from
appearing when the user right-clicks on the page. Please be aware that users can
still disable JavaScript in their browser or use browser settings to override this
behavior, and it's generally not recommended to interfere with standard browser
functionality.
To prevent email harvesting by web crawlers, you can encode email addresses in
a way that requires JavaScript to decode them. You can use JavaScript to replace
encoded email addresses with their original form on page load.
Create an HTML file with an element where you want to display the obfuscated email
address. For this example, let's use a <span> element with an id attribute to make it
easy to reference with JavaScript:
<html>
<head>
<title>Obfuscate Email Address</title>
</head>
<body onload=”hideemail()”>
<script src="script.js"></script>
</body>
</html>
Create a JavaScript file (e.g., script.js) to obfuscate and display the email address:
// script.js
function hideemail()
In the JavaScript code, we first define the obfuscated email address by using
String.fromCharCode to convert a series of character codes into a string. Then, we
select the <span> element with the ID of "email" and set its inner HTML to display
the obfuscated email address. Additionally, we wrap the email address in an anchor
(<a>) element with the mailto link to allow users to click and open their default email
client to send an email.
When you open the HTML file in a web browser, you will see the obfuscated
email address on the page. Users can click on it to send an email, but it's less
accessible to email harvesting bots. Keep in mind that this is not foolproof, and more
advanced techniques may be necessary to further protect email addresses from web
scraping.
Remember that these techniques offer limited protection, and they may
inconvenience or deter legitimate users. They won't stop determined attackers, so
it's crucial to focus on security practices such as server-side validation,
authentication, and authorization, which are more robust ways to protect your web
application.