We help IT Professionals succeed at work.

ASP response.write code need to encode

goodluck11
goodluck11 used Ask the Experts™
on
we have an ASP file that its called via  bookmarlet that response writes javascript code

if we call it via bookmarlet its fine the js code will execute

but if called directly via url to the asp file, it will display the entire javascript code

how can we encode this so that does not display the entire source code ?

thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Hi,

I think it should work. Please refer a simple example I just made.

HTML.asp
<%
Dim HTML

HTML = "<HTML>" &_
		"<HEAD>" &_
		"<SCRIPT language='javascript' type='text/javascript'>" &_
		"alert('hello');" &_
		"</SCRIPT>" &_
		"</HEAD>" &_
		"<BODY>" &_
		"<DIV ID='div'></DIV>" &_
		"</BODY>" &_
		"<SCRIPT language='javascript' type='text/javascript'>" &_
			"document.getElementById('div').innerHTML = 'THIS JS CODE IS EXECUTED FROM ASP'" &_
		"</SCRIPT>" &_
		"</HTML>"

		Response.Write(HTML)
%>

Open in new window


Output:
01.png
02.png

Author

Commented:
Thanks for your reply, but its kind of hard to hide, even thought we replace 'THIS JS CODE IS EXECUTED FROM ASP' with the JS script that will be executed on the page, still displays the entire code there,, is that what you meant ?
Okay,

can you provide the test code snippet explaining your scenario for better understanding of the issue you are facing?

Author

Commented:
javascript:(function(){%20var%20d=document,s;%20%20try{s=d.standardCreateElement('script');}catch(e){};%20%20if(typeof(s)!='object')s=d.createElement('script');%20%20s.type='text/javascript';%20%20s.src='http://test123.com/test123.asp.asp';%20%20%20try{d.getElementsByTagName('head')[0].appendChild(s);}catch(e){%20window.location%20='http://localhost='+window.location;}})();

Open in new window

Multitechnician
Top Expert 2014
Commented:
you can dynamically add a javascript code in your page with the following code :

var myscript = document.createElement("script");
myscript.src = "path/to/the/javascript/file.js";
document.body.appendChild( myscript );

Open in new window

Author

Commented:
Thanks, but how can we encode the output js code written to the broswer ?
leakim971Multitechnician
Top Expert 2014

Commented:
no need to encode

Author

Commented:
hi, the asp does a response write as well as the javacript into the browser. if the .asp file is called directly then youll see the entire response write javascript code, how can we encode / protect it ?
leakim971Multitechnician
Top Expert 2014

Commented:
with a IIS server?

Author

Commented:
Yes IIS

Author

Commented:
I've requested that this question be deleted for the following reason:

didnt get the answer