Sep
27
2005
Just because sometimes I forget, here are some code fragments to import JavaScript, CSS, and PHP files.
JavaScript:
<script
type='text/javascript'
src='directory/file.js'>
</script>
CSS:
<style type='text/css' media='all'>
@import 'directory/file.css';
</style>
Icon:
<link
rel='Shortcut Icon'
href='directory/file.ico'
type='image/x-icon'>
PHP:
<?php @ require_once ('directory/file.html'); ?>
For the PHP import, by placing the @ symbol before require_once suppresses any error messages that might be generated in the included PHP file.
JSP:
<%@ include file='jspfile.jspi' %>
And, well, I guess the list can go on and on. You can use Struts Tiles to include other JSP snippets. I am sure that other languages and frameworks have the same functionality.
no comments | posted in CSS, HTML/XML, JavaScript, PHP, TechKnow
Sep
24
2005
Sometimes you might not want to allow guests to your website to view the HTML source code. You can disable the right click context menu by using the following bit of code in your page:
<body oncontextmenu='return false;'>
You can use this feature to prevent users from right clicking and saving an image from your site. This is support by IE and Firefox. I have seen sites use similar functionality to this to pop up an alert with a copyright message is a user tries to right click on an image.
Keep in mind that a user can always disable JavaScript altogether, view the source from the application menu, and/or even save the whole HTML file onto his/her desktop and view the source from Notepad.
1 comment | tags: context menu, html, javascript, oncontextmenu | posted in HTML/XML, JavaScript, TechKnow
Sep
17
2005
Sometimes your application requires holding data in a temporary file. I’ve had to do this when printing a PDF file. The following bit of code demonstrates how to create a temporary file and delete said file when the program terminates.
File temp = File.createTempFile("SomePrefix", ".pdf");
temp.deleteOnExit();
The file is created in the system’s temp directory, see the Java java.io.tmpdir property.
no comments | posted in Java, TechKnow
Sep
10
2005
If you want to use a greater than sign (>) in an XML document you need to escape it. I once had to meticulously look over a 120 MB xml file that was generating a parsing exception, the cause of the exception, a greater than sign. Escape the following characters they are intended as xml/html content.
< <
> >
& &
Let me also mention some common characters that I escape when working with HTML.
© © Copyright
  Space
< < <
> > >
& & &
no comments | posted in HTML/XML, TechKnow
Sep
8
2005
This piece of code, simple as it is, took me a long while to develop. I am not well versed in Visual Basic and yet needed to find the default printer. I searched in a 1000+ page book, all over the internet, and after a lot of trial and error got it working. This Visual Basic script code block returns the default printer:
' Returns the default printer
Function GetDefaultPrinter()
Set WshShell = WSCript.CreateObject("WScript.Shell")
sRegVal = "HKCU\Software\Microsoft\Windows "
sRegVal = sRegVal & "NT\CurrentVersion\Windows\Device"
sDefault = ""
sDefault = WshShell.RegRead(sRegVal)
sDefault = Left(sDefault, InStr(sDefault, ",") - 1)
GetDefaultPrinter = sDefault
End Function
no comments | posted in TechKnow, Visual Basic
Sep
4
2005
Currently my favorite IDE is Eclipse 3.1.0. For this inaugural Eclipse Tool Tip, I will just mention a time saver of a feature. When creating a new JavaBean, start by defining the attributes. Once this is done, go to Source > Generate setters and getters. This will open a wizard to allow you to select the attributes which you will generate setter and getter methods. This feature will save you minutes of repetitive ‘cut and paste’ programming.
no comments | posted in IDE, TechKnow