Wednesday, November 20, 2013
Ajax Loader, $.getJSON Loader,
Just copy Paste on ur Script top,
It defines globally so no need add again and again for ajax events. It will fire for the jQuery Ajax events.
var cssOverlayOption = {
"position": "fixed",
"top": 0,
"left": 0,
"width": "100%",
"height": "100%",
"background-color": "#000",
"filter":"alpha(opacity=50)",
"-moz-opacity":"0.5",
"-khtml-opacity": "0.5",
"opacity": "0.5",
"z-index": 10000
};
var loaderImageCenter = {
"position":"relative",
"top":"50%",
"left":"50%"
};
var overlay = jQuery('<div id="overlay"><img src="images.jpg" id="loaderImage" width="99" height="102" title="Loading..." align="middle" /> </div>');
overlay.appendTo(document.body);
$(document).ajaxStart(function() {
$("#loaderImage").css(loaderImageCenter);
$("#overlay").css(cssOverlayOption).show();
});
It defines globally so no need add again and again for ajax events. It will fire for the jQuery Ajax events.
var cssOverlayOption = {
"position": "fixed",
"top": 0,
"left": 0,
"width": "100%",
"height": "100%",
"background-color": "#000",
"filter":"alpha(opacity=50)",
"-moz-opacity":"0.5",
"-khtml-opacity": "0.5",
"opacity": "0.5",
"z-index": 10000
};
var loaderImageCenter = {
"position":"relative",
"top":"50%",
"left":"50%"
};
var overlay = jQuery('<div id="overlay"><img src="images.jpg" id="loaderImage" width="99" height="102" title="Loading..." align="middle" /> </div>');
overlay.appendTo(document.body);
$(document).ajaxStart(function() {
$("#loaderImage").css(loaderImageCenter);
$("#overlay").css(cssOverlayOption).show();
});
Sunday, June 23, 2013
Detect Browser in php, User agent detection in php
function detect_mobile()
{
if(preg_match('/(alcatel|amoi|android|avantgo|blackberry|benq|cell|cricket|docomo|elaine|htc|iemobile|iphone|ipad|ipaq|ipod|j2me|java|midp|mini|mmp|mobi|motorola|nec-|nokia|palm|panasonic|philips|phone|playbook|sagem|sharp|sie-|silk|smartphone|sony|symbian|t-mobile|telus|up\.browser|up\.link|vodafone|wap|webos|wireless|xda|xoom|zte)/i', $_SERVER['HTTP_USER_AGENT']))
return true;
else
return false;
}
$mobile = detect_mobile();
if($mobile === true)
{
header("location:mobiledevice/index.php");
}
else
{
echo '<h3>you are looking via system browser</h3>';
/*echo $_SERVER['HTTP_USER_AGENT'];*/
}
{
if(preg_match('/(alcatel|amoi|android|avantgo|blackberry|benq|cell|cricket|docomo|elaine|htc|iemobile|iphone|ipad|ipaq|ipod|j2me|java|midp|mini|mmp|mobi|motorola|nec-|nokia|palm|panasonic|philips|phone|playbook|sagem|sharp|sie-|silk|smartphone|sony|symbian|t-mobile|telus|up\.browser|up\.link|vodafone|wap|webos|wireless|xda|xoom|zte)/i', $_SERVER['HTTP_USER_AGENT']))
return true;
else
return false;
}
$mobile = detect_mobile();
if($mobile === true)
{
header("location:mobiledevice/index.php");
}
else
{
echo '<h3>you are looking via system browser</h3>';
/*echo $_SERVER['HTTP_USER_AGENT'];*/
}
Detect Browser in Javascript, User agent detection in Javascript
<script type="text/javascript">
var ismobile = navigator.userAgent.match(/(alcatel) | (amoi) | (android) | (avantgo) | (blackberry) | (benq) | (cell) | (cricket) | (docomo) | (elaine) | (htc) | (iemobile) | (iPhone) | (ipad) | (ipaq) | (ipod) | (j2me) | (java) | (midp) | (mini) | (mmp) | (mobi) | (motorola) | (nec-) | (nokia) | (palm) | (panasonic) | (philips) | (phone) | (playbook) | (sagem) | (sharp) | (sie-) | (silk) | (smartphone) | (sony) | (symbian) | (t-mobile) | (telus) | (vodafone) | (wap) | (webos) | (wireless) | (xda) | (xoom) | (zte)/i);
if(ismobile)
{
// window.location = 'https://www.google.com.my';
alert("You are using mobile");
}
else
{
// window.location = 'https://www.yahoo.com';
alert("You are using system");
}
</script>
var ismobile = navigator.userAgent.match(/(alcatel) | (amoi) | (android) | (avantgo) | (blackberry) | (benq) | (cell) | (cricket) | (docomo) | (elaine) | (htc) | (iemobile) | (iPhone) | (ipad) | (ipaq) | (ipod) | (j2me) | (java) | (midp) | (mini) | (mmp) | (mobi) | (motorola) | (nec-) | (nokia) | (palm) | (panasonic) | (philips) | (phone) | (playbook) | (sagem) | (sharp) | (sie-) | (silk) | (smartphone) | (sony) | (symbian) | (t-mobile) | (telus) | (vodafone) | (wap) | (webos) | (wireless) | (xda) | (xoom) | (zte)/i);
if(ismobile)
{
// window.location = 'https://www.google.com.my';
alert("You are using mobile");
}
else
{
// window.location = 'https://www.yahoo.com';
alert("You are using system");
}
</script>
Tuesday, June 4, 2013
Href click submit jQuery, Simple JQuery validation, Form submit and reset jQuery. Self refresh jQuery
How to submit form with anchor tag/ href/a click in jquery?
Reload and Reset form jquery?
Simple validation in Jquery
// bind "click" event for links with title="submit"
$("a#submitcontact").click( function(){
// it submits the form it is contained within
$(this).parents("#register-form").submit();
});
$("#register-form").submit(function() {
var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
//$("#inline").empty().append('abc');
var address = $("input[name=Email]").val();
var emailError = true;
if($("input[name=Nama]").val() == ''){
$("#inline").empty().append('Please enter your Name.');
$('#Nama').focus();
return false;
}
else if($("textarea[name=Alamat]").val() == ''){
$("#inline").empty().append(' Please enter your Alamat');
$('#Alamat').focus();
return false;
}
else if($("input[name=Email]").val() == ''){
$("#inline").empty().append(' Please enter your E-mail address');
$('#Email').focus();
return false;
}
else if(!reg.test(address)) {
//emailError = true;
$("#inline").empty().append('Please enter your valid E-mail address.');
$('#Email').focus();
return false;
}
else if($("input[name=NoTelp]").val() == ''){
$("#inline").empty().append('Please enter your NoTelp.');
$('#NoTelp').focus();
return false;
}
else if($("textarea[name=Pesan]").val() == ''){
$("#inline").empty().append(' Please enter your Pesan');
$('#Pesan').focus();
return false;
}
else{
return true;
}
});
$("a#reseter").click( function(){
// it submits the form it is contained within
//opener.location.reload(true);
window.location.href = "contact.html";
// $(this).closest('form').find("input[type=text], textarea").val("");
// $(this).parents("#register-form").reset();
});
});
Wednesday, May 29, 2013
Location based Auto currency Updater in PHP, Currency and Update with two different sites..
$exectime = microtime();
$exectime = explode(" ",$exectime);
$exectime = $exectime[1] + $exectime[0];
$starttime = $exectime;
function get_geo_ip_code_wtanka($ipaddr)
{
set_time_limit(3); /// time in second 3 sec if it will take more then means next function will be load..
$userip = file_get_contents("http://geoip.wtanaka.com/cc/".$_SERVER['REMOTE_ADDR']);
$userip = strtolower($userip);
return $userip;
}
//echo $userip;
function get_geo_ip_code_sourceforge($ipaddr)
{
$userip = file_get_contents("http://ip2country.sourceforge.net/ip2c.php?format=JSON&ip=$ipaddr");
$userip = str_replace('"','',$userip);
$userip = '"'.$userip.'"'; /* it will returns u the JSON formate however u want u can change*/
$otup = json_decode($userip);
$otup = str_replace('{','',$otup);
$otup = str_replace('}','',$otup);
$otup = explode(',',$otup);
$len = count($otup);
$new = array();
for($i=1;$i<$len;$i++)
{
$rite = explode(':',$otup[$i]);
$new[] = array($rite[0]=>$rite[1]);
}
$value = strtolower($new[1]['country_code']);
$value = $value;
return $value;
}
$userip = get_geo_ip_code_wtanka($_SERVER['REMOTE_ADDR']) ;
$exectime = microtime();
$exectime = explode(" ",$exectime);
$exectime = $exectime[1] + $exectime[0];
$endtime = $exectime;
$totaltime = ($endtime - $starttime);
$ipaddr =$_SERVER['REMOTE_ADDR'];
if($totaltime>=3 || !file_exists("http://geoip.wtanaka.com/cc/$ipaddr") )
$userip = get_geo_ip_code_sourceforge($_SERVER['REMOTE_ADDR']);
Tuesday, January 8, 2013
Php - RSS feed into website
<?php
$feed = file_get_contents('http://samplesite.com/index.rss');
$rss = new SimpleXmlElement($feed);
foreach($rss->channel->item as $values) {
//var_dump($value);
//print_r($value);
//echo "<a href='$value->link' title='$value->title' target='_blank' >" . $value->title . "</a>";
}
?>
TIPS :
un-cmd var dump and view source .... u will getta good idea to split how u want....
un-cmd the print_r u will geta correct key values of the feed.....
Hope it will be useful this
Subscribe to:
Posts (Atom)