Javascript
Passing JavaScript variables to PHP
by Binod on Aug.28, 2011, under Javascript, PHP, Tips & Tricks, Tutorial, Web Designing
What if I can pass variables between 2 scripting language. JavaScript is mainly used as a client side scripting language, while PHP is a server side technology. Unlike Java or ASP.Net, PHP doesn’t have tools to make it work client side. That is why you need to combine JavaScript and PHP scripts to develop powerful web-applications.
One of the frequent problems is defining visitor’s screen resolution using JavaScript tools and passing this data to PHP-script. The following script provides solution for this problem:
<!—index.htm –>
<script type=”text/javascript”>
width = screen.width;
height = screen.height;
if (width > 0 && height >0) {
window.location.href = “http://localhost/main.php?width=” + width + “&height=” + height;
} else
exit();
</script>
Copy and paste this code snippet in the text editor, save it as index.htm and run it in your browser. After this code has been executed, a user is automatically redirected to the main.php page where screen resolution is displayed in the browser window.
The main.php looks as follows:
<!—main.php –>
<?php
echo “<h1>Screen Resolution:</h1>”;
echo “Width : “.$_GET['width'].”<br>”;
echo “Height : “.$_GET['height'].”<br>”;
?>
As you can see, passing JavaScript variables in PHP is similar to sending data using GET method.
Auto refresh page
by Binod on Dec.12, 2010, under Javascript, Tutorial
Here i tried to explains how to refresh the page in a certain interval of time. Sometime you need to refresh the page automatically while using the session. You need to load the latest content automatically . So the webpage needs to be refreshed.
Sample code
<script type=”text/JavaScript”>
function autoRefresh(timeToRefresh) {
setTimeout(“location.reload(true);”,timeToRefresh);
}
</script>
<p><a href=”javascript:autoRefresh(1000)”>Refresh page in 1 sec</a></p>
Hope this will help u a lot…
Browser Detection
by Binod on Nov.19, 2010, under Javascript, Tutorial
Javascript has given us a feature to detect the browser that the client is using in his computer.
1) Browser CodeName: navigator.appCodeName ( Eg. Mozilla )
2) Browser Name: navigator.appName ( Eg. Netscape
3) Browser Version: navigator.appVersion ( Eg. 5.0 (Windows; en-US) )
4) Cookies Enabled: navigator.cookieEnabled ( Eg. true )
5) Platform: navigator.platform ( Eg. Win32 )
6) User-agent header: navigator.userAgent ( Eg. Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12 )
Example:
document.write(“Browser CodeName: ” + navigator.appCodeName);
document.write(“<br /><br />”);
document.write(“Browser Name: ” + navigator.appName);
document.write(“<br /><br />”);
document.write(“Browser Version: ” + navigator.appVersion);
document.write(“<br /><br />”);
document.write(“Cookies Enabled: ” + navigator.cookieEnabled);
document.write(“<br /><br />”);
document.write(“Platform: ” + navigator.platform);
document.write(“<br /><br />”);
document.write(“User-agent header: ” + navigator.userAgent);