i am developing a website, i want disable print screen so i searched in the net and i used a JavaScript to disable print screen. it worked fine but during loading of a page it asks for the permission to access the clipboard.
the pop-up message that it shows,
"do u want to allow this webpage to access your clipboard?
If you allow this, the webpage can access the clipboard and read information that you've cut or copied recently.. "
i want to avoid the above pop-up message and also disable print screen.
Below is my JavaScript code.:
function AccessClipboardData() {
try {
window.clipboardData.setData('text', "Print Disabled");
} catch (err) {
}
<body>
<script language="JavaScript" type="text/javascript">
setInterval("AccessClipboardData()", 300);
var ClipBoardText = "";
if (window.clipboardData) {
ClipBoardText = window.clipboardData.getData('text');
ClipBoardText = window.clipboardData.clearData('text');
if (ClipBoardText == "") {
alert('Sorry you have to allow the page to access clipboard');
document.all("divmaster").style.display = "none"
}
}
</script>
</body>
can please help to solve that print screen and clip board problem.
thanks in advance..
You must be trying to protect your page from theft or copy.
But I have only one to say to you. If the website loads on the clients computers, it means all the contents including images to markup all of them are stored on the client's PC and then displayed on the browser window. So, not matter what you do, there is never a final solution for this.
So, I suggest you to do not go down this road.
<input name="Print1" onclick="javascript:window.print();" type="button"
value="Print1" align="right"/> use this
onclick="javascript:window.print();" type="button" value="Print1" align="right"
Related
I want to save some JavaScript code as a bookmark in chrome so it automatically opens my university login site and clicks on on the login button. I am completely inexperienced in JavaScript, so I have no clue how to do this. I snipped together the following code, which opens the correct website, but then does not click on anything. The first URL automatically puts me to the login site (third URL in the code) in case I have not logged in yet in this window.
(function() {
window.location.replace("https://lms.uzh.ch/auth/MyCoursesSite/0");
window.onload = function(){
if (current_url.startswith('https://lms.uzh.ch/auth/MyCoursesSite/0')) {
return;
}
if (current_url.startsWith('https://lms.uzh.ch/dmz/')) {
document.getElementById("wayf_submit_button").click();
}
};
})();
I'm sorry if this is too obvious a question and annoys any experts but as I said I am a complete beginner. I would of course add the "javascript:" at the beginning for chrome to understand the bookmark.
When you use window.location.replace, you change the address and you code can't work anymore.
I can suggest using some browser extension, your "click function" should work then.
I guess you could also try to make some simple html page with iframe, you call your "click function" at this page, but you target it to the iframe. After that you can change browser's location to the university's webpage as you should already be logged in.
<html>
<head>
</head>
<body>
<iframe src="your_university_address.com" id="some_id" onload="click_button()"></iframe>
<script>
function click_button()
{
my_iframe=document.getElementById('some_id');
my_iframe.contentDocument.getElementById('your_button_id').click();
}
</script>
</body>
</html>
Very simple but it should do that job.
(You can achieve similar result by using window.open() I guess)
I wrote this script to pop-up a message any time a user clicks on an external link from our site. When I wrote this I assumed the best way to do this would be to check location.host and compare it to the url the user is attempting to visit.
<script type="text/javascript">
$(function(){
$('a').click(function(){
if (this.href.match(location.host)) {
//alert('Please continue on to our site.');
window.onbeforeunload = null;
}
else {
if (window.confirm('NOTICE: By accessing this link, you will be leaving the DBPR website. DBPR is not responsible for the content of the Internet website you are entering. DBPR neither warrants nor makes any representations nor endorsements as to the accuracy, quality, content or completeness of the information, text, images, graphics, hyperlinks, and other items contained on the Internet website you are entering. DBPR is not responsible or liable for any viruses or contaminations of your hardware, software, peripherals or property, resulting from use of the Internet websites linked to or from the DBPR Internet website. Do you want to proceed?')
){
// They clicked Yes
}
else
{
// They clicked no
return false;
}
}
});
});
</script>
The way the code currently stands, it works in the majority of cases, however I noticed that a couple buttons on our home page reference javascript:void(0), and they cause the confirm box to prompt on click .
Is there a way you would recommend to treat javascript:void(0) as an internal link or completely diregard it?
Thanks,
TG
You could do it like this:
if (this.href.match(location.host) ||
this.href.toLowerCase().indexOf('javascript') !== -1) {
// allow
}
I would like to write a html page where clicking on the hyperlink can be traced. That means I can get a statistic about how many people click on a hyperlink in my page, in a past period. If it is possible to know their ID, it would be better.
And I find this piece of code from the source of a web page:
<script type="text/javascript">
function stc(e,linkIndex) {
if (document.images) {
var linkText;
if (navigator.appName.toLowerCase()=="microsoft internet explorer") {
linkText=e.innerText}
else {
linkText=e.textContent}
if (linkText=="") {
if (e.firstChild) {
var firstChild=e.firstChild.nodeName.toUpperCase();
if (firstChild=="IMG") {
linkText="Image: "+getName(e.firstChild.getAttribute('src'))}}
else {
var nodeName=e.nodeName.toUpperCase();
if (nodeName=="AREA") {
linkText="ImageMap: "+e.href}}}
if (linkText=="") {
linkText=e.href}
(new Image()).src="/a/i/stg.gif?f="+escape(document.location.href)+"&t="+escape(e.href)+"&i="+linkIndex+"&n="+escape(trimString(linkText))}}
function getName(s) {
if (s.lastIndexOf('/')>=0) {
return(s.substring(s.lastIndexOf('/')+1,s.length))}
else {
return(s)}}
function trimString(s) {
return(s.replace(/^\s*/,"").replace(/\s*$/,""))}
</script>
and I guess google will be able to track information of clinking on this link.
I don't know too much about Javascript, could anyone tell me, according to this code, where the tracing information is saved?
usually trace() in other languages is is just some kind of output and the best most simple way to do that in javascript is to call console.log("some output "). you can view the output in Google Chrome by right click on the page > inspect element, then click on the console tab, there you will see your output. in Firefox, you should get the Firebug add-on, there you can see the same output generated by console.log("some output") again within the console tab.
other browsers suck for dev so why even bother explaining?
You need serverside code to do this.
For example, you could have a gateway script that redirects users to the page they want to see:
http://www.example.com/portal/www.google.com/
From there, you can just save the user's request into a database and redirect the user to www.google.com almost instantly without the user really caring.
I have been to some css/html/js discussing board which provide a text box to enter the html and a "Run it!" button to run the html in new pops up window.
I want to make one also, which is easy in jQuery:
function try_show_result() {
var code = $("#try-input").val();
if (code !== "") {
var newwin = window.open('','','');
newwin.opener = null; // 防æ¢ä»£ç 修改主页
newwin.document.write(code);
newwin.document.close();
}
}
But then I found a security problem: the pops up window has all the abilities of running an arbitrary javascript. So that when another authenticated user runs a given piece of code on the page, then it could stealing cookies or access some url that is only for the specified user only through ajax posts.
Is there an easy way to avoid this?
Update: I added newwin.document.cookie="" before open the window, not sure if this is better.
Is there an easy way to avoid this?
No
That is why Facebook went out and wrote their own version of JavaScript [FBJS].
JavaScript doesn't allow you to update window.location without triggering a reload. While I agree with this policy in principle (it shouldn't be possible to visit my website and have JavaScript change the location bar to read www.yourbankingsite.com,) I believe that it should be possible to change www.foo.org/index to www.foo.org/help.
The only reason I care about this is for bookmarking. I'm working on a photo browser, and when a user is previewing a particular image, I want that image to be the default if they should bookmark that page. For example, if they are viewing foo.org/preview/images0-30 and they click on image #15, that image is expanded to a medium-sized view. If they then bookmark the page, I want the bookmark URL to be foo.org/preview/images0-30/active15.
Any thoughts, or is there a security barrier on this one as well? I can certainly understand the same policy being applied here, but one can dream.
Sounds like you should check out Really Simple History. It's how Google (for example, Gmail) allows any page to be bookmarkable (and has history) but doesn't refresh the whole page.
As for the other side of things (having people visit your site then automatically popping up the correct image), I'd try checking window.location.hash once the page loads and firing events based on that.
You can add an anchor to the URL without reloading the page and pick that up with javascript:
location.href = '.../#' + imageId;
As mentioned, generally with ajaxy sites, you manipulate/check the hash part of the URL (window.location.hash) to determine this kind of activity.
The biggest issue is making sure to check against the hash in DOM-ready/window-load, as if the user clicked on a given image. This will work with browsers and bookmarks, but may hamper search indexing.
How about detecting on page load if the URL contains a hash, and if it does, directing them to the page you want them to go to?
You can add [Add to Favorites] button on the page.
Sample:
var urlAddress = "http://www.example.com/#image1";
var pageName = "Example Page Title - Image1";
function addToFavorites() {
if (window.external) {
window.external.AddFavorite(urlAddress, pageName);
} else {
alert("Sorry! Your browser doesn't support this function.");
}
}
Or use one of these jQuery plugins:
http://plugins.jquery.com/project/bookmark
http://plugins.jquery.com/project/jqbookmark
http://plugins.jquery.com/project/AddFavourite
http://plugins.jquery.com/project/jFav
http://plugins.jquery.com/project/jBookmarkEngine
AND / OR
Use URLs with hash at the end and load your content (images etc.) based on that hash value.
function onLoad() {
if (window.location.hash == "image1") {
// load image1
}
}
There are also lots for jQuery plugins for working with URL hash events, for example:
http://plugins.jquery.com/project/hashhistory
http://plugins.jquery.com/project/hashchange
There are also lots of non jQuery JavaScript libraries for that, for example:
http://code.google.com/p/reallysimplehistory/
<html>
<head>
<script type="text/javascript">
function myHref(){
document.getElementById('myAnchor').innerHTML="Visit Google"
document.getElementById('myAnchor').href="http://www.google.com"
}
</script>
</head>
<body>
<a id="myAnchor" href="http://www.java2s.com">Visit Java2s</a>
<form>
<input type="button" onclick="myHref()" value="Change URL and text">
</form>
</body>
</html>