Showing posts with label source code. Show all posts
Showing posts with label source code. Show all posts

Javascript: Disabling right click on a web page

Want to protect your source code?

Using this code will prevent the vast majority of users from right-clicking over a page and choosing "View source", or right-clicking over an image and saving it. There are other ways to view the code, though... This is not always a wise technique to use - it would have to be a very special piece of code to want to hide, and those who would want to steal it will always be able to find a way to see it.

1. Disable right click script

<SCRIPT TYPE="text/javascript">
<!--
//Disable right click script
function clickIE() {if (document.all) {(message);return false;}}
function clickNS(e) {if
(document.layers(document.getElementById&&!document.all)) {
if (e.which==2e.which==3) {(message);return false;}}}
if (document.layers)
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}
document.oncontextmenu=new Function("return false")
// -->
</SCRIPT>



2. To disable the IE imagetoolbar also add the META TAG below to the HEAD

<META HTTP-EQUIV="imagetoolbar" CONTENT="no">


3. To protect TEXT add 'Disable Text Select' code below into of your HTML.


<SCRIPT TYPE="text/javascript">
<!--
//Disable select-text script (IE4+, NS6+)
function disableselect(e){
return false
}
function reEnable(){
return true
}
//if IE4+
document.onselectstart=new Function ("return false")
//if NS6
if (window.sidebar){
document.onmousedown=disableselect
document.onclick=reEnable
}
// -->
</SCRIPT>


Enjoy!

Before you leave:
Do you find this article useful? Any suggestion, question or comment? Please post it in the comments below.

Read Users' Comments (0)

CD Autorun for HTML File

When a CD is inserted into a PC, Windows looks for a file called autorun.inf. This file can contain many options, but at its simplest it just tells Windows to run a command, as in the example below:

[autorun]
open=program.exe

You can insert any command you like into this file, and once the requested command is in the PATH environment variable, it will run.

Opening a HTML file.
In order to open a data file, such as a HTML file, automatically, the autorun.inf needs to call the Windows Start command. Running a command such as start index.html should run the application associated with HTML files and open index.html within that application. You would think that a simple autorun.inf like this would do the trick:

[autorun]
open=start index.html

However, this doesn't seem to work in most cases. So we have developed a really simple application that passes on your requested parameters to Windows, and can be used to start any program when a CD is inserted. This simple, free program, called RunCmd can be downloaded using this link:

http://cdrunner.50webs.com/downloads/RunCmd.zip

Once you have downloaded the Zip file (4Kb), unpack the executable file (7Kb) and place it in the root of your CD file structure when you are burning your CD.

Then, to get that CD to automatically open a HTML file, you need to copy the autorun.inf to the root folder of the CD, alongside the RunCmd.exe. This autorun.inf file should contain the command to tell RunCmd.exe to open the HTML file:

[autorun]
open=RunCmd.exe start index.html

You can change the text index.html in the autorun.inf file to the name of the file you want to open automatically, including its relative path if it is not in the root folder. This will then automatically open the required file when the CD is inserted into a Windows PC.

The RunCmd.exe utility is an extremely simple, ANSI C program of about 30 lines. I am copying below the source code (C File), can compile and used instead of downloading zip file.

#include "stdio.h"
#include "string.h"

#define MAX_CMD_SIZE 128

int main(int argc, char* argv[])
{
char cmdStr[MAX_CMD_SIZE];
int i = 1;
cmdStr[0] = 0;

while(i < argc)
{
if((strlen(cmdStr) + strlen(argv[i]) + 1) < MAX_CMD_SIZE)
{
strcat(cmdStr, argv[i]);
strcat(cmdStr, " ");
}

i++;
}

printf("Executing command: \"%s\"", cmdStr);

if(strlen(cmdStr))
{
system(cmdStr);
}

return 0;
}

Read Users' Comments (0)