Thursday, February 21, 2013

Alert JS loss focuss on browser tab

Alert JS loss focus on browser tab


You may have seen alert massages appear in browsers when you change from one tab to another this is done by Java script on blur function.This example shows you following alert box


 Create HTML page using  Following code to generate above alert

<script type="text/javascript">
window.onblur = function () {

    alert('loss of focus on this tab,you will not get any point');
}
</script>
<h1>Loss of Focus JS</h1>

Thursday, January 10, 2013

Object Drag & Drop in flash

Object Drag & Drop in flash

Using flash action script 2.0 you and drag and drop object in the stage first download a suitable image i used bellow picture

  Next open flash action script 2.0 document import image into stage modify the the document larger than the image imported.then insert new layer draw rectangle over the image. (1/4th of the image) select rectangle then covert to movie clip symbol name as MC_shape and give instance name also as MC_shape.Make other new 3 layers and draw 3 rectangles to cover the image next convert to movie clips give name and instance name as mc_shape1,mc_shape2&mc_shape3 


Stage look like as bellow

Next insert new layer name as actions right click 1st frame of actions layer go to actions plane write the bellow scripts

MC_shape.onPress = function(){
MC_shape.startDrag();
}
MC_shape.onRelease = function(){
MC_shape.stopDrag();
}
MC_shape1.onPress = function(){
MC_shape1.startDrag();
}
MC_shape1.onRelease = function(){
MC_shape1.stopDrag();
}
MC_shape2.onPress = function(){
MC_shape2.startDrag();
}
MC_shape2.onRelease = function(){
MC_shape2.stopDrag();
}
MC_shape3.onPress = function(){
MC_shape3.startDrag();
}
MC_shape3.onRelease = function(){
MC_shape3.stopDrag();
}
Then go control test movie


Wednesday, January 9, 2013

Custom Cursor in flash

Custom Cursor in flash 

 


AS bellow image you can customize the cursor shape with flash

 
First import a suitable image to the flash stage then modify document according to the image size and align to the stage.Name the layer as image insert new layer and draw a circle name the layer as cursor as bellow.

 
Then covert the circle into  symbol movie clip name as cust_cursor and give instance name also as cust_cursor
Modify--->convert to symbol


when the movie clip is selected press f9 in the key board next type the bellow scripts in the action window.

onClipEvent (enterFrame) {
 Mouse.hide();
 startDrag(this, true);
}

Then controle---> text movie


Thursday, January 3, 2013

Image alpha change in flash

Image alpha change in flash

                                                          Day
                                                      Night


First import images to flash document in different  layers name as bellow


Now go to the day layer select image go to modify--->Convert to symbol type Movie clip dialog box fill as bellow

Then select day layer image give the instance name as fader_mc
select action layer press F9 button then action window appears type the bellow scripts  in the action window.

 mouseInterval=setInterval(changeAlpha,10);
function changeAlpha() {
fader_mc._alpha=Math.round

(_root._xmouse/550*100)
}


Now go to control-->Test Movie you can see the alpha changes mouse over other image


Thursday, December 13, 2012

Auto Fill second input box js

Auto Fill second input box Java Scripts 




when you fill first  input box above second one fills automatically by using the Java Scripts bellow

<html>
<head>
<script type="text/javascript">
    function copy_data(val){
     var a = document.getElementById(val.id).value
     document.getElementById("copy_to").value=a
    }

    </script>
</head>
<body>
<input type="text" name ="a" id="copy_from" onkeyup="copy_data(this)"/>
<input type="text" name ="a" id="copy_to"/>
</body>
</html>

Thursday, December 6, 2012

Elapse time, cookies name and last visited, page load time Java Scripts



Elapse time, cookies name and last visited, page load time Java Scripts 


Following piece of java Scripts code will show you cookie name and the date of last visited the site.

<!DOCTYPE html>
<html>
<head>
<script>
function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
  {
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if (x==c_name)
    {
    return unescape(y);
    }
  }
}

function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}

function checkCookie()
{
var username=getCookie("username");
if (username!=null && username!="")
  {
  alert("Welcome again " + username);
  }
else
  {
  username=prompt("Please enter your name:","");
  if (username!=null && username!="")
    {
    setCookie("username",username,365);
    }
  }
}
</script>
<script type = "text/javascript">



var days = 730;
var lastvisit=new Object();
var firstvisitmsg="This is your first visit to this page. Welcome!";
lastvisit.subsequentvisitmsg="Welcome back visitor! Your last visit was on <b>[displaydate]</b>";

lastvisit.getCookie=function(Name){
var re=new RegExp(Name+"=[^;]+", "i");
if (document.cookie.match(re))
return document.cookie.match(re)[0].split("=")[1];
return'';
}

lastvisit.setCookie=function(name, value, days){
var expireDate = new Date();

var expstring=expireDate.setDate(expireDate.getDate()+parseInt(days));
document.cookie = name+"="+value+"; expires="+expireDate.toGMTString()+"; path=/";
}

lastvisit.showmessage = function() {
var wh = new Date();
if (lastvisit.getCookie("visitc") == "") {
lastvisit.setCookie("visitc", wh, days);
document.write(firstvisitmsg);
}

else {
var lv = lastvisit.getCookie("visitc");
var lvp = Date.parse(lv);
var now = new Date();
now.setTime(lvp);
var day = new Array("Sun", "Mon", "Tues", "Wed", "Thur", "Fri", "Sat");
var month = new Array ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
var dd = now.getDate();
var dy = now.getDay();
dy = day[dy];
var mn = now.getMonth();
mn = month[mn];
yy = now.getFullYear();
var hh = now.getHours();
var ampm = "AM";
if (hh >= 12) {ampm = "PM"}
if (hh >12){hh = hh - 12};
if (hh == 0) {hh = 12}
if (hh < 10) {hh = "0" + hh};
var mins = now.getMinutes();
if (mins < 10) {mins = "0"+ mins}
var secs = now.getSeconds();
if (secs < 10) {secs = "0" + secs}
var dispDate = dy + ", " + mn + " " + dd + ", " + yy + " " + hh + ":" + mins + ":" + secs + " " + ampm
document.write(lastvisit.subsequentvisitmsg.replace("\[displaydate\]", dispDate))
}

lastvisit.setCookie("visitc", wh, days);

}

lastvisit.showmessage();

</script>
</head>
<body onload="checkCookie()">
</body>
</html>

Bellow codes of Java Scripts shows you elapse time stayed in a specific page as countdown timer 

<html>
<head>
<title>load</title>

<Script Language="JavaScript">

var startDate = new Date();
var startTime = startDate.getTime();

function seconds_elapsed ()
{
var date_now = new Date ();
var time_now = date_now.getTime ();
var time_diff = time_now - startTime;
var seconds_elapsed = Math.floor ( time_diff / 1000 );

return ( seconds_elapsed );
}

function time_spent ()
{

var secs = seconds_elapsed ();


var mins = Math.floor ( secs / 60 );
secs -= mins * 60;


var hour = Math.floor ( mins / 60 );
mins -= hour * 60;


document.display.timeElapsed.value = pad ( hour ) + ":" + pad ( mins ) + ":" + pad ( secs );


setTimeout( "time_spent ()", 1000 );
}

function pad ( num )
{
return ( ( num > 9 ) ? num : "0" + num );
}
</Script>
</head>

<body onLoad="time_spent()">

<form name="display">
<input name="timeElapsed" type="text" size=8>
</form>

</body>
</html>

Following codes are really php in which you can find the tame taken to page load. 

<html>
<head>
</head>
<body>
<?php
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$finish = $time;
$total_time = round(($finish - $start), 4);
echo 'Page generated in '.$total_time.' seconds.';
?>
<body>
<html>

Tuesday, December 4, 2012

HTML Save as word doc

HTML Save as word doc

HTML body content could be save as Microsoft word document by using PHP file as bellow including header information to save as word document.

<?php
  
header("Content-type: application/vnd.ms-word");
  
header("Content-Disposition: attachment; Filename=SaveAsWordDoc.doc");
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Windows-1252\">
<title>Saving HTML as a Word Doc</title>
</head>

<body>
<table border=1 align="center">
<tr><td>Name</td><td>Age</td></tr>
<tr><td>Mark Taylor</td><td>34</td></tr>
<tr><td>Oksana dassie</td><td>32</td></tr>
<tr><td>Oksana Babiac</td><td>38</td></tr>
<tr><td>karina kpoor</td><td>22</td></tr>
<tr><td>Alisa diction jonson</td><td>48</td></tr>
</table>
</body>
</html>