How can someone else see Your webpage code?

Source: Internet
Author: User

Statement: these methods are of no use to a master. Therefore, you can do it if you have a spear.

1. Add the following code to the <body> </body> of HEML.

 

<SCRIPT language = javascript>
Function click () {if (event. button = 2) {alert (You are not allowed to peek !);}} Document. onmousedown = click
</SCRIPT>
2. Prohibit viewing web page source code

It is impossible to create a .htm with the actual source code! The Source Code cannot be blocked. Using TELEPROT can download any file, which is equivalent to an image website, unless the server performs security settings and encryption.

Below are several reference methods, so that you cannot use the right-click or view the source code or source code when browsing my personal homepage.

1) enter the code on the homepage:

<SCRIPT language = javascript>
Function click (){
If (event. button = 2 ){
Alert (Sorry, disable this function ^_^ .)
}
}
Document. onmousedown = click
</SCRIPT>
<Script language = "JavaScript">
<! --
Locate = 0;
Function scroller (){
If (locate! = 500 ){
Locate ++;
Scroll (0, locate );
ClearTimeout (timer );
Var timer = setTimeout ("scroller ()", 3 );
Timer;
}
}
// -->
</Script>
2) webpage Security Technical Guide

With the rapid development of the Internet, the number of websites is increasing at a geometric level, and the information on webpages is greatly enriched. However, the security and copyright of websites are constantly threatened. recently, major websites around the world have been attacked by hackers. In order to adapt to the new situation, the first website on network security (Skynet security front) in China was born. the security of websites and webpages has received more and more attention. This article will introduce various technologies and techniques for enhancing the security of webpages from a simple perspective, it is of great help to readers who care about the copyright of the webpage source code and the security protection of webpage data.

For the majority of Web Page writers, source code protection is the most concerned, but often there is no way. the pages that have worked so hard to write are invisible to viewers. You only need to right-click the page and select (View Source Code) to obtain the complete code of the page, even after a slight modification, it becomes another person's webpage. this article uses JavaScript technology to modify the page source code, so that the browser cannot obtain the source code to protect the code.

First, you should shield the Internet Explorer Toolbar-view-source code function, that is, the page uses the framework structure. if your page does not use a frame structure and does not need a frame structure, you can use the "zero frame" Technology (that is, the page is divided into two frames, the width of the Left frame is 1, right frame is the original page ). the code for this method is as follows:

<Html>
<Head>
<Title> welcome to taobao.com </TITLE>
</HEAD>
<Frameset cols = "1, *" frameborder = 0 framespacing = 0>
<Frame src = "PS. HTM" NAME = "count" noresize scrolling = no>
<Frame src = "search. HTM" NAME = "search" noresize>
</Frameset>
</Html>
Save the file as the primary file index.htm, and create an empty file ps.htm. the original page file is index.html (slightly different from the primary file name only on the Extension). The zero-frame technology has the following advantages:

1. The page Code cannot be directly obtained from the source code items in the toolbar, but only the code of the main framework file (that is, the above Code) can be obtained ).

2.use the left frame file ps.htm to load some advanced Web applications, such as background music, web page counters, and cookie applications.

The following code is added to the page file (index.html file in the previous example) that is to be protected (the prompt box shown in Figure 1 appears when the right button is clicked)

<Script Language = "JavaScript">
Function click (){
If (event. button = 2 | event. button = 3) {alert ("right-click? "^_^ )}}
// The quotation marks indicate that the parameter can be customized.
Document. onmousedown = click
</Script>
Finally, the following code should be added to the protected page to prevent some people who know the programming language of the webpage from manually finding the protected page through the connection in the main file of the framework to obtain the source code:

<Script language = "javascript">
If (top = self) top. location = "index.html"
</Script>
This code will automatically jump back to the Framework main file index.html to protect the page.

After completing the above three steps and modifying your home page according to the framework structure, the source code of your home page will not be available to viewers on the Internet. You can just celebrate it.

In addition, if you do not want to use a framework page, you can use a special method to open a new window in the browser, and then use the code to mask the mouse to receive the same effect. The method to open the page is as follows:

<A href = javascript: window. open ("key.html", "protected page title", "height = 170, width = 290, left = 0, top = 0, toolbar = 0, location = 0, directories = 0, status = 0, menubar = 0, scrollbars = 0,

Resizable = 0, copyhistory = 0 ") target = _ blank> connect to the protected page </a>
In the code, key.html is the file name of the protected page. The height and width of the new window can be customized by the user, in pixels.

Note: embedded JavaScript code should be added to the

The above is the use of JavaScript technology to protect online web pages. The so-called "strong middle hand" should be changed to the following code:

<Script>
Window.location.replace(index1.html) // This sentence generates the webpage jump function
</Script>
For the offline browsing function (working offline) added by Internet assumer5, the preceding method sometimes fails. You can set cookies for webpages to protect them. once the cookie expires, even if the webpage has been downloaded to the local machine, it cannot be viewed :)

The cookie code segment to be added to the file is as follows:

<Script language = "JavaScript">
Function getCookieVal (offset)
{
Var endstr = document. cookie. indexOf (";", offset );
If (endstr =-1)
Endstr = document. cookie. length;
Return unescape (document. cookie. substring (offset, endstr ));
}
Function GetCookie (name)
{
Var arg = name + "= ";
Var alen = arg. length;
Var clen = document. cookie. length;
Var I = 0;
While (I <clen)
{
Var j = I + alen;
If (document. cookie. substring (I, j) = arg)
Return getCookieVal (j );
I = document. cookie. indexOf ("", I) + 1;
If (I = 0)
Break;
}
Return null;
}
Function SetCookie (name, value)
{
Var argv = SetCookie. arguments;
Var argc = SetCookie. arguments. length;
Var expires = (2 <argc )? Argv [2]: true;
Var path = (3 <argc )? Argv [3]: true;
Var domain = (4 <argc )? Argv [4]: true;
Var secure = (5 <argc )? Argv [5]: true; // The security mode takes effect.
Document. cookie = name + "=" + escape (value) +
(Expires = null )? "": ("; Expires =" + expires. toGMTString () +
(Path = null )? "": ("; Path =" + path) +
(Domain = null )? "": ("; Domain =" + domain) +
(Secure = true )? "; Secure ":"");
}
Function ResetCounts (name)
{
Visits = 0;
SetCookie (expdate, "/", true, true );
Location. reload ();
}
</Script>
<Script language = "JavaScript">
Var expdate = new Date ();
Var visits;
Expdate. setTime (expdate. getTime () + (24*60*60*1000); // sets the cookie expiration time, which is 1 day.
If (! (Visits = GetCookie ("visits ")))
Visits = 0;
Visits ++;
SetCookie (expdate, "/", true, true );
</Script>
If you have already done this, the protection of your webpage is no longer that simple.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.