Current location: Hot Scripts Forums » General Web Coding » JavaScript » Can it be done?


Can it be done?

Reply
  #1 (permalink)  
Old 12-21-04, 07:01 AM
boxkites's Avatar
boxkites boxkites is offline
Newbie Coder
 
Join Date: Feb 2004
Location: New Zealand
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Can it be done?

Hi all
Newbe here, I would like to include a no right click within the new generated window, I have tried several times [3 hours] to put the all familliar no right click code in there somewhere, but I get nothing but errors.
I GIVE UP.
I just want to make an attempt to stop people from copying sensitive images. Yes I know it cant be done 100% but at least It will appear that I am trying.
Does anybody know where and what to insert to get the job done?
Perhaps it can't be done this way, Thanks in advance.
Oh and have a Merry X-Mas all.

Steady Breezes
Robert

Here is the code.
No, I didn't write it, I borrowed it from somewhere, he at least I am honest!

<SCRIPT language="JavaScript">

var width,height
var image,ext
var cond1,cond2
function transferview(image,width,height) {

cond1="width="+(width+20)+"";
cond2="height="+(height+62)+"";

var s1 ="<HTML>"
var s2 ="<TITLE>.:: Bar-x.nl ::.</TITLE>"
var s3 ="<BODY BGCOLOR=#000000>"
var s4 =""
var s5 ="<table align='center' cellpadding=0 cellspacing=0 border=0><tr><td><a href='#' onclick='window.close();return false'><IMG SRC='"+image+"' BORDER=0></a></td></tr>"
var s6 ="<tr><td align='center' height='40' valign='bottom'><a href='#' onclick='window.close();return false'><img src='images/close.jpg' width='140' height='28' alt='Sluit Deze Raam' border='0'></a></td></tr></table>"
var s7 ="</BODY></HTML>"

ImageWindow=window.open("", "newwin"+width,"toolbar=no,scrollbars="+scroll+",m enubar=no,"+cond1+","+cond2);
ImageWindow.document.write(s1+s2+s3+s4+s5+s6+s7)
ImageWindow.document.close()
}
</SCRIPT>

Last edited by boxkites; 12-21-04 at 07:14 AM. Reason: submitted to quick DOH!!!
Reply With Quote
  #2 (permalink)  
Old 12-22-04, 09:06 AM
TwoD TwoD is offline
Community VIP
 
Join Date: Sep 2003
Location: 404
Posts: 1,813
Thanks: 0
Thanked 0 Times in 0 Posts
Since the script has all the HTML that goes into the new window stored in text strings, you would have to put the no-right-click script in those strings, otherwise it won't be in the new window.

Using Javascript to write other Javascripts to a page is a bit tricky at first.
One common mistake is doing somehting like this:

Code:
<script>
function Test(){
  document.body.innerHTML+="<script>alert('hello')</script>"
}
</script>
If you write </script> the browser might think the current script has ended, and thus it halts the code and produces an error. Do "</scr"+"ipt>" instead to make the </script> closing tag harmless until it has been written to the page.

I noticed that you don't have a closing </head> in the script.
If you switch s3 and s4, you can put the script in the s3 string and end it with </head>.
Just make sure to put a backslash "\" before all "s and 's in the no-right-click code or the browser thinks the string is broken.
Reply With Quote
  #3 (permalink)  
Old 12-22-04, 06:35 PM
boxkites's Avatar
boxkites boxkites is offline
Newbie Coder
 
Join Date: Feb 2004
Location: New Zealand
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks TwoD

Ok, I have changed it to this[see below] I don't get the errors anymore but the picture that should appear, in the generated popup, doesn't show and the no right script doesn't work on that page either.
I would like to display about 500 images this way and I don't want to make an html page for every image, that is why I would like to use this script. I would like to use this on several websites I manage.
I suppose I could also do this in PHP using some album script, but that is a different story.
I know the bug is in the "var s3" line somewhere because if I leave the line out the generated page looks ok, just doesn't have the no right click applied to it. As soon as I put it back the page does pop up but it is blanc, Nada!

Thanks for helping out.
Robert



var s1 ="<HTML><HEAD>"
var s2 ="<TITLE>.:: www.Softkites.com /Bristol Photo's ::.</TITLE>"
var s3 ="<script language=JavaScript>var message=\'\'; function clickIE() {if (document.all) {(message);return false;}}function clickNS(e) {if (document.layers||(document.getElementById&&!docum ent.all)) {if (e.which==2||e.which==3) {(message);return false;}}}if (document.layers) {document.captureEvents(Event.MOUSEDOWN);document. onmousedown=clickNS;}else{document.onmouseup=click NS;document.oncontextmenu=clickIE;}document.oncont extmenu=new Function(\'return false\')\'</scr\'\'+ipt\'></HEAD>"
var s4 ="<BODY background=images/pixi_darkgrey.gif text=orange>"
var s5 ="<table align='center' cellpadding=0 cellspacing=0 border=0><tr><td><a onclick='window.close();return false'><IMG SRC='"+image+"' border=0 ></a></td></tr>"
var s6 ="<tr><td align='center' height='40' valign='top'>Click on image to close this window.</td></tr></table>"
var s7 ="</BODY></HTML>"
Reply With Quote
  #4 (permalink)  
Old 12-23-04, 03:53 PM
TwoD TwoD is offline
Community VIP
 
Join Date: Sep 2003
Location: 404
Posts: 1,813
Thanks: 0
Thanked 0 Times in 0 Posts
Code:
<script language=JavaScript>
var message=\'\';	*
function clickIE(){
	if (document.all){
		(message);	*
		return false;
	}
}
function clickNS(e){
	if(document.layers||(document.getElementById&&!document.all)){
		if (e.which==2||e.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\')	*

\'</scr\'\'+ipt\'>	*
This is how the no-right-click script would look if you broke it apart into individual lines again.
I've put a star on the lines with errors or other problems.

The first star isn't really an error and it won't affect the script.
I know I said that you should escape all "s and 's with slashes.
If you use "s around the s3 string like you did, any "s inside the code will cause the browser to
throw an error. This happens because it thinks the s3 string has ended and the rest of the line is garbage, unless
you put a slash before the other "s inside the s3 string to tell the browser they are part of the string.
The same goes for 's.
However, if you use only 's inside a string eclosed in "s there won't be an error because the browser knows the string
has not ended, it hasn't encountered the closing " yet. It works the other way around too of course.

But, if you need to nest "s and 's you'll get troubles unless you tell the browser to ignore the "s and 's by
putting slashes in front of them. Keeping track of nested "s and 's is a whole science lol.

With all that said, I'm sorry I tricked you into placing those slashed in there since they are not really needed in this script.

Back to the stars...
The second problem will cause an error. I think whoever made the script wanted the user to place an alertbox or something on
this row so that the visitor will know right-clicking is disabled.
The same thing goes for the third star, but this time it's for Netscape users.
Either completely remove those lines, or replace them with something like this: alert('No right clicking here!');

The fourth star marks the same 'problem' as the first one.

The last line should be like this: </scr"+"ipt>
Maybe I was a bit unclear there too, all you need is to break the s3 string into two and add them together to make the
browser ignore the closing </script> tag. I've noticed that this isn't always neccessary but I always do it just to be sure.

Here's the whole s3 string:

Code:
var s3 ="<script language=JavaScript>var message=''; function clickIE() {if (document.all){return false;}}function clickNS(e){if(document.layers||(document.getElementById&&!document.all)){if(e.which==2||e.which==3){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')</scr"+"ipt></HEAD>"
I think that was all that needed to be done. Hope it works and Merry Christmas!
Reply With Quote
  #5 (permalink)  
Old 12-24-04, 02:21 AM
boxkites's Avatar
boxkites boxkites is offline
Newbie Coder
 
Join Date: Feb 2004
Location: New Zealand
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Hi All
This is just a follow up on the atricle.
Thanks to TwoD I now have the script working just fine.
You can view it in action at:
www.softkites.com/dieppe.php

Merry Christmas all and a happy new year.

Robert
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 10:37 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.