Sunday, April 25, 2010

Disable your site from Greasemonkey !!!

I've found this by an accident!!!

 document._createElement = document.createElement;
 document.createElement = function(tagName, password) {
    if (tagName != "SCRIPT" || password == "My scripts are OK!") {
        return document._createElement(tagName);
    }
 };
just that and your site will be protected

Tuesday, March 24, 2009

javascript to show and hide element

for html you need to define ID name of an element

<input type="button" name="clickme1" id="clickme1" value="Click me !!" onclick="JavaScript:showbutton('clickme2')"><BR>
<input type="button" name="clickme2" id="clickme2" value="Click me !!" onclick="JavaScript:showbutton('clickme1')" style="visibility:hidden">
For javascript need this code
function showbutton(idName){
 Element = document.getElementById('clickme2');
 Element.disabled=true;
 Element.style.visibility = "hidden";
 Element = document.getElementById('clickme1');
 Element.disabled=true;
 Element.style.visibility = "hidden";
 clickme1Element = document.getElementById(idName);
 clickme1Element.disabled=false;
 clickme1Element.style.visibility = "visible";
}

Thursday, November 20, 2008

countdown javascript display in div

window.onload = function() {
startCountDown(180, 1000, myFunction); // set setdown here
}
function startCountDown(i, p, f) {
var pause = p;
var fn = f;
var countDownObj = document.getElementById("countDown");
if (countDownObj == null) {
alert("div not found, check your id");
return;
}
countDownObj.count = function(i) {
countDownObj.innerHTML = i;
if (i == 0) {
fn();
return;
}
setTimeout(function() {
countDownObj.count(i - 1);
},
pause
);
}
countDownObj.count(i);
}
function myFunction() {
alert("hi alex");
}
and put div name
<div id="countDown"></div>

Monday, September 22, 2008

javascript validate array checkbox

we can pass value through php and validate checkbox by these

<html>
<html>
<head>
<script language="JavaScript">
function check()
{
 var a=document.some_form['graduate[]'];
 alert("Length:"+a.length);
 var p=0;
 for(i=0;i<a.length;i++){
  if(a[i].checked){
   alert(a[i].value);
   p=1;
  }
 }
 if (p==0){
  alert('please select at least one check box');
  return false;
 }
 document.some_form.submitted.value='yes';
 return true;
}
</script>
</head>
<body>
<form name="some_form" onsubmit="return check();" method="POST" action="">
<table>
<tr><td>Post Graduate in</td><td>
<input type="checkbox" name="graduate[]" value="history">History
<input type="checkbox" name="graduate[]" value="telugu">Telugu
<input type="checkbox" name="graduate[]" value="Computer sceince">Computer Science
<input type="checkbox" name="graduate[]" value="Mathematics">Mathematics

</td></tr>
<tr><td><input type="submit" value="Submit"></td></tr>
<input type="hidden" name="submitted">
</form>
</body>
</html>
<?php
if ($_POST[submitted])
{
$pg=$_POST[graduate];
echo "<pre>";
print_r($pg);
echo "</pre>";
}
?>
ref : www.programmersheaven.com

Monday, August 25, 2008

javascript unique array

function unique(a) {
  var temp = [];
  var temp2 = [];
  for (c in a)
  temp[a[c]] = c
  for (c in temp)
  temp2[temp[c]] = c
  return temp2;
}

Wednesday, August 06, 2008

Another javascript highlighter

Insert head section with
<style type="text/css">@import url(http://retsam.krad.googlepages.com/jush.css);</style>
<script type="text/javascript" src="http://retsam.krad.googlepages.com/jush.js" defer="defer"></script>


and in body with
<body onload="jush.highlight_tag('pre');">

Your source code in pre tag here
<pre class="jush">
input source code here
</pre>


Don't forgot to change < to &lt;

All your code will look like this
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> <?php print_r($_POST['title']); ?> </TITLE>
<script type="text/javascript" src="prettify.js"></script>
<script type="text/javascript">
document.onload=temps();
document.onload=setTimeout('chargement();sec=10;',3000);
var x=window.confirm("Are you sure you are ok?")
if (x) window.alert("Good!")
else window.alert("Too bad")
</script>

</HEAD>
<BODY>
<font color="red">TESTING red</font>
<font color="#0f0f0f">TESTING red</font>
<table>
<!-- HTML COMMENT-->
<?
print_r('POST:'.$_POST.'<BR>');
print_r('GET :'.$_GET);
function Google(){
print_r($_POST);
}
?>

<TR><TD>TEST table TR TD</TD><TD>TEST table TR TD 2</TD></TR>
<input value="test" name="test">
</BODY>
</HTML>

Thursday, July 17, 2008

Magic wand mouse script

simple add the following script into the <BODY> section of your page

Tuesday, June 17, 2008

javascript get all link in page

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function LinkList() {
var myheader = "<head><title>Links In "+document.title+"</title></head>";
myheader = myheader + "<body>";
var myfont = "<font style="font: 8pt Verdana, Arial, Helvetica, Sans-serif; line-height:18pt;" face="verdana, tahoma, geneva" size="-1" >";
var mytext = "<center><b>Links in " + document.title + "</b><ol></center>";
var myendfont = "</font>";
var myendheader = "</body>";

windowprops = "menubars=no,location=no,toolbars=no,scrollbars=yes,"+"width=350,height=400,top=50,left=50";
self.name = "main";

if(document.all) {
for (i=0; i<document.links.length; i++) {
if(document.links[i].innerText)
if(document.links[i].innerText != " ")
mytext += "<li><a target='_new' href="+document.links[i]+">"+document.links[i].innerText+"</a><br>";
else
mytext += "<li><a target='_new' href="+document.links[i]+">"+document.links[i]+"</a><br>" ;
   }
}
else {
for (i=0; i<document.links.length; i++) {
if(document.links[i].text) {
if(((document.links[i].text).indexOf("javascript:")) == -1) {
mytext += "<li><a target='_new' href="+document.links[i]+">"+document.links[i].text+"</a><br>" ;
   }
}
else { }
   }
}
mytext = mytext + "</ol><center><a href='javascript:window.close()'>close</a></center><BR>";

linkswin = window.open("","",windowprops);
with (linkswin.document) {
open();
write(myheader + myfont + mytext + myendfont + myendheader);
close();
   }
}
//  End -->
</script>
From : The JavaScript Source!!

Sunday, June 08, 2008

prettifier javascript sourcecode syntax highlighter for blogger

easy as it does not much to configure with prettifier highlighter
1.download and see the instruction here
2. copy these code and paste befor </head>

<link href='YOUR_SITE/prettify.css' rel='stylesheet' type='text/css'/>
<script src='YOUR_SITE/prettify.js' type='text/javascript'/>
3) Wrap your code and Remember to replace < with <lt; , & with &amp;
<pre class="prettyprint">
<?php
    //comment start here
    /*and can start here*/
    #and here
    class Highlighters() {
        function result($highlighter) {
            switch ($highlighter) {
               case "chili":
               default:
                  return "FTL";
               case "syntaxhighlighter":
                  return "FTW";
            }
        }
    }
 for($i=0;$i<10;$i++){
  print_r($_POST[$i])
  return true;
  return null;
 }
    $highlighters = new Highlighters();
    printf("Chili is a nice effort, but just not for me.  Chili %s", $highlighters->result("chili"));
    printf("I am going to give SyntaxHighlighter a shot.  SyntaxHighlighter %s", $highlighters->result("syntaxhighlighter"));
?>
<HTML>
<BODY onload='init();'>
TESTING HELLO WORLD
</BODY>
</HTML>
</pre>
the css is not pretty as its name but you can modify is yourself From: http://code.google.com/p/google-code-prettify/

Saturday, June 07, 2008

javascript sourcecode syntax highlighter for blogger

I've got new things what i've find for a while HOW to user SyntaxHighlighter easy 3 step to complete this highlighter
1) Include the core files and the brushes for any language you want. Your paths may be different.

    <script type="text/javascript" src="/syntaxhighlighter/js/shCore.js"></script>
    <script type="text/javascript" src="/syntaxhighlighter/js/shBrushPhp.js"></script>
    <script type="text/javascript" src="/syntaxhighlighter/js/shBrushJScript.js"></script>
    <script type="text/javascript" src="/syntaxhighlighter/js/shBrushXml.js"></script>
2) Put this at the end of your file. If you put it before the code you want highlighted it won’t work.
<script class="javascript">
dp.SyntaxHighlighter.ClipboardSwf = "syntaxhighlighter/js/clipboard.swf";
dp.SyntaxHighlighter.HighlightAll("code");
</script>
3) Wrap your code and tell SyntaxHighlighter which brush to use. Remember to replace < with &lt; , & with &amp;
<pre name="code"  class="php">
<?php
    class Highlighters() {
        function result($highlighter) {
            switch ($highlighter) {
               case "chili":
               default:
                  return "FTL";
               case "syntaxhighlighter":
                  return "FTW";
            }
        }
    }
 for($i=0;$i<10;$i++){
  print_r($_POST[$i])
 }
    $highlighters = new Highlighters();
    printf("Chili is a nice effort, but just not for me.  Chili %s", $highlighters->result("chili"));
    printf("I am going to give SyntaxHighlighter a shot.  SyntaxHighlighter %s", $highlighters->result("syntaxhighlighter"));
?>
<HTML>
<BODY onload='init();'>
TESTING HELLO WORLD
</BODY>
</HTML>
</pre>
From : http://www.pseudocoder.com/ For blogger.com following this link

Thursday, June 05, 2008

create DIV element on page

these script are to create DIV element on page with javascript
that can be define you size of header and navigator pane
by these variable headerHeight ,menuWidth
for future AJAX request to build your website


function createBlankpage(){
    var totalWidth = 0, totalHeight = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        totalWidth = window.innerWidth;
        totalHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        totalWidth = document.documentElement.clientWidth;
        totalHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        totalWidth = document.body.clientWidth;
        totalHeight = document.body.clientHeight;
    }
    var headerHeight = 150;
    var menuWidth = 170;
    var menuTop = headerHeight+'px';
    var menuHeight = totalHeight-headerHeight+'px';
    var mainTop =menuTop;
    var mainLeft = menuWidth;
    var mainWidth = totalWidth-menuWidth+'px';
    var mainHeight = menuHeight;
    createDiv('headerDIV','0px','0px',totalWidth,headerHeight);
    createDiv('menuDIV','0px',menuTop,menuWidth,menuHeight);
    createDiv('mainDIV',mainLeft,mainTop,mainWidth,mainHeight);
}

function createDiv(id,left,top,width,height,color){
    var id,top,left,height,width,visible;
    var creatingDiv = document.createElement("DIV");
    creatingDiv.id = id;
    creatingDiv.style.position="absolute";
    creatingDiv.style.left= left;
    creatingDiv.style.top= top;
    creatingDiv.style.width= width;
    creatingDiv.style.height= height;
    creatingDiv.style.verticalAlign="middle";
    creatingDiv.style.zIndex=5;
    creatingDiv.style.visibility = "visible";
    creatingDiv.innerHTML = "";
    document.body.appendChild(creatingDiv);
}

Saturday, May 31, 2008

AJAX http request

testdata.html

<html>
<script type="text/javascript" src="httpxml.js"></script>
<a href="#" onclick="javascript:requestData('target.php', '', 'myForm1', 'divName', '', 'post', '', '', '');">post data from myForm to target.php and display in divName</a><BR>
</html>

instruction in xmlhttp.js file xmlhttp.js

Tuesday, May 06, 2008

redirect page with php,javascript,mata tag

Redirect with php code:

<?php
header
('Location: http://retool2.myminicity.com/');
include(
'countlink.php');
?>


Redirect with java script:
<HEAD>
<SCRIPT language="JavaScript">
<!--
 function getgoing()
  {
    top.location="http://retool2.myminicity.com/";
   }
 
   if (top.frames.length==0)
    {
     setTimeout('getgoing()',7000);
     }
//-->
</SCRIPT>
</HEAD>


Redirect with meta tag:
<meta http-equiv="refresh" content="5;url=http://retool2.myminicity.com"/>