Disable copying data from webpage - asp.net

I was looking for any way to create web page,so that user wont be able to copy content from my web page. i.e. User wont be able to select the any text present on the webpage.
Let's assume i am working on asp.net
Any interesting ideas to accomplish the task ?

Ultimately you can't.
If you disable the ability to select text, the context menu or even just the copy option from the context menu users will still be able to see your content.
If they can see it they can copy it:
Take a screenshot.
Take a photo.
Type the text they see into Notepad.
Dictate the text into a recorder.
It's not worth the development effort and you won't stop the determined copier. All you'll end up doing is annoying your legitimate users.
Add value to your site so people want to keep coming back rather than just taking content and running. This could be:
Allow user generated content to expand on what's there.
Update content regularly so it's always fresh.

You can use user-select CSS3 propertie
HTML like this :
<span class="protected">Datas you wants protect</span>
And the correspondant CSS :
.protected {
-moz-user-select:none;
-webkit-user-select:none;
user-select:none;
}
See my example : http://jsfiddle.net/DoubleYo/RPv4q/
This solution is not cross browser but work fine with firefox and chrome/safari
EDIT : advanced user can copy your content with view the page source, make pdf or print your page, and some people mention firebug, fiddler.

If you send down any text the user will be able to see the source, so disabling copy and paste by any method will not really help stop the determined copier.
The most effective approach would be to render your text in to an image on the server and send down the image and not the raw text, but before you do that there are several downsides to consider: 1) You will require capacity on your server to generate the image. 2) The data load will be higher than just text and compresion will be less effective. 3) You may also loose some caching options.
Is there a particular reason you don't want the user to copy the text, perhaps if you can provide more details other approaches may be possible?

Try this
<html>
<head>
<script language="<strong class="highlight">javascript</strong>">
function onKeyDown() {
// current pressed key
var pressedKey = String.fromCharCode(event.keyCode).toLowerCase();
if (event.ctrlKey && (pressedKey == "c" ||
pressedKey == "v")) {
// <strong class="highlight">disable</strong> key press porcessing
event.returnValue = false;
}
} // onKeyDown
</script>
</head>
<body>
<form name="aForm">
<input type="text" name="aText" onkeydown = "onKeyDown()">
</form>
</body>
</html>

When someone visits your website they receive the html/css/images/JavaScript that makes up the bulk of your site. So they already have your Content, as most browsers cache this too, to allow quicker browsing.
Read more on HTTP here - http://www.http.header.free.fr/http.html
So it is not quite possible to totally stop anyone that know how the http protocol works. But what you can do is to maybe listen for right clicks and stop normal end users from right clicking and saving a image etc. You can get a snippet here - http://www.dynamicdrive.com/dynamicindex9/noright.htm
But if you are talking about protecting images/files that are selling please have a look at Protect html/php/image files from tracking as it then applies to your problem.

You can add to your body tag like so:
<body onselectstart="return false">

This is Internet. You can't completely protect the content of the page.
But you can difficult this task for the user.
You can too handle keyboard and mouse inputs, like Ctrl+C or right click of the mouse.
But remember that the user can always see the source code of the page, copy it and paste on a HTML editor.
You can make your site in Silverlight or Flash, but this will "disable" search engines indexing.

convert your page into a image

You can disable the selection, and with out selection you do not have copy/paste, however I suggest do that only on some parts of your page because is frustrate for the user.
This is the simple code that you can do that, eg, if you have a div with id="notme", run the disableSelOnThis("notme");
function disableSelOnThis(IdName) {
var oElem = document.getElementById(IdName);
if (oElem)
disableSelection(oElem); }
function disableSelection(element) {
element.onselectstart = function() {
return false;
};
element.unselectable = "on";
element.style.MozUserSelect = "none";
element.style.cursor = "default";
}
The code was from : http://ajaxcookbook.org/disable-text-selection/ , but its seams that this site is not longer live.
Of course without javascript enable this is not working and everything ChrisF says still stands.

Just copy and Paste the below javascript in your webpage:
<script language="javascript" type="text/javascript">
function disableselect(e) {
return false
}
function reEnable() {
return true
}
document.onselectstart = new Function("return false")
if (window.sidebar) {
document.onmousedown = disableselect // for mozilla
document.onclick = reEnable
}
function clickIE() {
if (document.all) {
(message);
return false;
}
}
document.oncontextmenu = new Function("return false")
var element = document.getElementById('tbl');
element.onmousedown = function () { return false; } // mozilla
</script>
Note:If the above code not works for Firefox then add style="-moz-user-select:none" in the body tag which needs to be restricted alongwith the above code.

Related

Mailto: via CSS stopped working years ago

Clicking on the mailicon.gif button (or typing the 'm' key) used open the standard mail program with the To: and Subject: fields already filled out, but this has stopped working.
html:
<img src="mailicon.gif">
css:
a.myMail:active {background:url('mailto:my.address#xmail.com?subject=Some Feedback');}
Nowadays it only adds the # to the url in the browser-addressline, screen stays the same and nothing more happens. How can I restore the old behavior?
Your mailto should be defined on the href (the link), you linked to just #, css is for styling:
<img src="mailicon.gif">
Thanks again for your remarks, and having the ‘mailto’ in the html in principle is the proper way to go if you have only 1 or 2 mailaddresses.
I probably over-simplified my question by just showing the 2 lines of coding. The problem I faced was a bit larger, i.e. not one email address but several. Therefore, a long time ago I implemented what I specified in those 2 lines of coding. In reality I had more than 50 html files and x classes: class=”Anne” class=“Boris”, class=”Charlie” and so on.
Having the mail-addresses in the one css file, used by all html files, made life easy, and it did work, I’m sure of that.
In the meantime css and browsers have evolved, matured and some rules have changed, that’s probably why it is not working anymore.
Nevermind, instead of those 50 html files I now have only 1 html file, 1 javascript file and many JSON files, each containing a short description of a number of photographs. One of the items in there is the name of the photographer.
This name is displayed as an image below the picture, and when one clicks on that image, the program tries to open the default mail-program to send a mail.
It now works as follows in the javascript file:
var emailinfo = '#domain.com?subject=Website%20Fotos%20Feedback';
function HandleKeyDown(e) {
....
else if (e.keyCode == 77) { // m keyboard shortcut to start mail-program
SendEmail();
]
}
function SendEmail() {
if (!copyrightname == '') {
window.open('mailto:'+copyrightname.toLowerCase()+emailinfo);
}
}
function LoadText(elt) {
....
if (elt.copyright) {
copyrightname = elt.copyright; // used later when 'm' is clicked or copyrightmsg is clicked.
temp = '<img src="icons/cr_' + elt.copyright + '.gif" title="Click here to send a mail.">';
$("#copyright").html(temp); // show the image below the picture
}
else {copyrightname = '';}
....
}
$(document).ready(function() {
$(document).keydown(HandleKeyDown);
$("#copyright").click(SendEmail);
....
}
For the time being it works in FF.
IE gives warning that mailprog was not correctly defined, Chrome opens a blank window. These of course are different problems so I’m gonna work on those now.
Hope you now see why I can't have the complete name in the only html file I have.
See it working (in FF) on wijchman.com and then click on the (big) icon with the small pictures.
Thanks for reading so far and your suggestions.

How to change css style locally and save this changes

i have an webapp and i need to onclick change css style, but i need to save this change in the webapp instaled into the phone of my user, and only in his phone. The javascript for onclick change css style it's working but i don't have no idea to how to save this css changes.
Can somebody help me with this?
Since now thanks
In general CSS styles can't be directly saved on an HTML client.
What you can do is make an Ajax call back to your server and save the information there. The next time the user asks for the page send HTML with the appropriate style class already on the element you wish to style based on the saved information.
There are several hackish client side possibilities involving JavaScript & cookies or local storage but I would avoid that sort of solution if at all possible since it's very likely to lead to an annoying flicker as the page loads and renders styled one way and then the JavaScript finally runs and corrects the style.
To elaborate on my comment:
el1.addEventListener('click', function() {
el2.style.color = 'red';
localStorage['color'] = el2.style.color;
})
And then on startup:
window.addEventListener('load', function() {
if (localStorage['color']) {
el2.style.color = localStorage['color'];
}
}
Of course, you may want to add error checking and fallbacks as appropriate.

meteor - live code update to webpage?

I'm curious to know whether Meteor would be suitable for following, and how I would go about writing the code.
I'd like to create a webpage, where by the code in a specific "div" can be hotswapped on the fly to users currently looking at that page. (eg. the div contains some text, but then an image replaces it.) Ideally, the swap would be executed manually by the the webpage's admin through the click of a button, or some code fired off on the server or something. Regular viewers to the webpage would not be able to do this - they only see the live changes on the page.
real-life example:
live internet broadcast is off-air, therefore the "div" contains "off-air" text. live hotswap of code happens when broadcast goes on-air, and the viewers of the webpage now see the html5 broadcast player in the "div" instead. later it is swapped back once the broadcast goes off-air.
I'm completely new to the Meteor platform, so I consider myself a newbie :) Any help is appreciated.
You might better off by using a reactive div using data from a collection (I'm going to use an example with raw HTML but you might be better off implementing your own functionality with what content to display instead: i.e
Basically take advantage of reactivity over hot code swaps
Client side html code
<template name="home">
<div>
{{{content}}}
</div>
</template>
js code
if(Meteor.isClient) {
MyCollection = new Meteor.Collection("MyCollection")
Template.home.content = function() {
if(MyCollection.findOne()) {
return MyCollection.findOne().content
}
}
}
if(Meteor.isServer) {
MyCollection = new Meteor.Collection("MyCollection")
//Set an initial content if there is nothing in the database
Meteor.startup(function() {
if(!MyCollection.findOne()) {
MyCollection.insert({content:"<h1>Test content</h1><p>Test Data</p>"
}
}
//A method to update the content when you want to
Meteor.methods({
'updatecontent':function(newcontent) {
id = MyCollection.findOne()._id
MyCollection.update(id, {$set:{content:newcontent}});
return "Done"
}
}
You can update your content either in the mongo collection or with something like (in your web console, client side or server side javascript):
Meteor.call("updatecontent","New content",function(err,result) {
if(!err) {
console.log(result)
}
});
Which will update the code live when you use it.
I'm sorry it's quite long but the bulk of it is setting/updating the html. Its actually much nicer than a hot code swap which would refresh the user's page

To disable the addressbar and standardbuttons bar in IE when my application lanches?

when my application launches in the IE from start page to main page i want to hide the addressbar and the standardbuttons bar of IE through the codebehind and here am using masterpage concept so i have to write the code in master only i think so....can anyone help for this
AFAIK you cannot disable address bar and button in IE from when the application starts unless using some ActiveX, Flash, ... Only if your application opens new window popups you could hide them.
I just found a way... It works atleast in IE 7... Not sure about other browsers...
<html>
<head>
<script>
if (window.name == 'default') {
window.name = 'Hai';
window.open('main.html', '_self'); // Current html file name
}
else if(window.name == '') {
window.name = 'Hai';
window.open('main.html', '_self'); // Current html file name
}
else if(window.name == 'Hai') {
// Use your application startup page here along with the desired options
window.open('newfile.aspx','NEWWINDOWNAME', 'Status=0, location=0');
window.close();
}
</script>
</head>
<body>
This window automatically closes itself
</body>
</html>
The complete list of options are available here.
Hope this helps.
Explanation : (AFAIK) Generally when javascript uses window.close method to close the active window, IE will ask for a confirmation from the user. Such confirmation will not be asked when the window is a popup window opened previously by a javascript along with a name.
The above just fakes the same, by opening the same file in the same window but this time with a name. As a result when window.close is executed, IE recognises the current window as a window opened using Javascript and as it also has a name, it just closes the same without confirmation.
Of course, I get a general Javascript alert at the beginning of the load, but since (I presume) you will be using aspx or other types, this problem will not be there.

How to make a link that makes the page their homepage or a bookmark?

Is there a simple way to create a link that does either?
Basically, I would like a very simple way to do this. Any suggestions are helpful.
In just IE:
Bookmark This Site
In firefox and IE:
function addBookmark(title, url) {
if (window.sidebar) { // firefox
window.sidebar.addPanel(title, url,"");
} else if( document.all ) { //MSIE
window.external.AddFavorite( url, title);
} else {
alert("Sorry, your browser doesn't support this");
}
}
<a href="javascript:addBookmark('My Site','http://www.mysite.com')>Add bookmark</a>
There are ways to add favorites using Javascript, although some browsers don't support it at all. You can find a script here that claims to offer a cross-browser method of adding a bookmark, but actually just tells the user what to press to open the Add Bookmark dialog on Firefox, for example.
In all cases, all that javascript can do is open the add bookmark dialog, and the user will still have to manually add the bookmark themselves.
Check this for adding the site to the user's bookmarks
You can use this code to set your page as the user's homepage.

Resources