Script Tips


NetBizCity - Script Tips
Tuesday, 28 April 2009 01:42

Time Left Counter

Written by

This script will give you a count down of Years, Months, Days and Hours left to a given date.

 

Enter a date as Month day, year

 

Click to see the days left

<script>
function cdtime( targetdate){

var currentTime=new Date()
var tdate=new Date(targetdate)
var timesup=false
var timediff=(tdate - currentTime)/1000
var oneHour=3600 //hour unit in seconds
var oneDay=86400 //day unit in seconds
var oneMonth=2630880 //month unit in seconds
var oneYear=31570560
var yearfield=Math.floor(timediff/oneYear)
timediff = timediff - (yearfield * oneYear)
var monthfield=Math.floor(timediff/oneMonth)
timediff = timediff - (monthfield * oneMonth)
var dayfield=Math.floor(timediff/oneDay)
timediff = timediff - (dayfield * oneDay)
var hourfield=Math.floor(timediff/oneHour)
if (currentTime >= tdate){
	var ret = "The time is up!"
}else{
	if (yearfield > 1){ret = yearfield + " Years " }else{ret = yearfield + " Year "}
	if (monthfield > 1){ret = ret + monthfield + " Months "}else{ret = ret + monthfield + " Month "}
	if (dayfield > 1){ret = ret + dayfield + " days and " }else{ret = ret + dayfield + " day and " }
	if (hourfield > 1){ret = ret + hourfield + " Hours left"}else{ret = ret + hourfield + " Hour left"}
}

return ret
}
</script>

To call it just place this code on your page.



document.write(cdtime("July 1, 2010"))
Sunday, 08 October 2006 03:10

Placing Text on a Picture

Written by

Placing Text on a Picture

One method we can use is using a table with the picture as the background

 

We can set the background for the column
and place the text within the TD tag as normal
<td background="mars_lander.gif" width="231" height="265" align="center" nowrap>
<h1><font color="yellow">Is there Life on Mars?</font></h1></td>

Is there Life

on Mars?

 

Another method we can use is using position or layers

For this example We will use the div tag
<div class="div_set"><br><br>Is there Life<br>on Mars?</div>

For the Style we have the following:

<STYLE>
     .div_set {z-index:1; background-image: url(mars_lander.gif);
     font-size:34; font-weight:bold; text-Align:center;
     color: yellow; position:relative; width: 231; height:265;}
</STYLE>
 

 

Is there Life

on Mars?

In both cases to avoid repeating the image use background-repeat:no-repeat

Vincent Gabriele

Tuesday, 17 August 2004 22:11

Dealing with file or Site inclusion

Written by

File Inclusion

The first three methods only allow local files to be included

Include method:
You can include files in sub folders for example file="include\include_example.htm"
Or you can include files in the parent folder or other parent sub folders for example:
Other subfolder: file="..\include\include_example.htm"
Parent folder: file="..\include_example.htm"
IIS Server Tip for referencing parent directory

For windows you must use an "asp" or shtml extension.
If you use shtml then you must have the include file within a directory that has execute set - cgi-bin will work.

Example File=

<!-- #include file="include_example.htm"-->

Example Virtual=

<!-- #include Virtual="include/include_example.htm"-->

ASP server.execute method:
<%server.execute "include_example.htm"%>

PHP include method
include "include/include_example.htm";
or
include ("include/include_example.htm");

These methods allow inclusion of files located on another server!

PHP under linux can allow file inclusion of files from other websites if allow_url_fopen is enabled.
This setting does not work in Windows as it is always disabled.

IFrame:
<iframe scrolling="no" border="0" frameborder="0" width="200" height="150" src="include_example.htm" mce_src="include_example.htm">
Your Browser does not support IFrames</iframe>

Object method:
<object style="border: 0.5cm groove orange" data="include_example.htm" type="text/html" height="130" width="250">
</object>

Screen Scrape with ASP .NET:
This method requires you to save the file with an ASPX extension.
<%@ Import Namespace="System.Net" %>

<script language="VB" runat="server">
    Sub Page_Load(sender as Object, e as EventArgs)
      Try
         'Create a WebClient instance
       Dim objWebClient as New WebClient()
 
       Const strURL as String = "http://www.httpsend.com"    
       Dim objUTF8 as New UTF8Encoding()
       lblHTMLOutput.Text = objUTF8.GetString(objWebClient.DownloadData(strURL))
       Catch webEx As WebException 'to avoid dot net system error'
           if webEx.Status = WebExceptionStatus.ConnectFailure then
                'do nothing
             end if
         End Try
      End Sub
</script>
<table width="100%" bgcolor="white">
      <tr>
            <td align="center">
                  <h1>Screen Scrape Example of www.httpsend.com</h1>
            </td>
       </tr>
</table>
      <asp:label id="lblHTMLOutput" runat="server" /> 

Vincent Gabriele

 

 

Script Tips Search

Registered User