23 December 2010

how to use redirect using Javascript

javascript
Redirects are useful when doing some work and needs to go to another page after finished the work.

For example : after showing successful login , you will be redirected to home page.

Using button as link using javascript inside HTML code:

<input type="button" value="Visit Google" onclick="window.location = 'http://www.google.com' "/>

Use one line code to redirect :

 window.location = "http://www.google.com" ;


Note: The window.location object can be used to get the current page address (URL) and to redirect the browser to a new page.

(If you found this article useful then share with your friends.)

how to get input value using javascript

javascript
Using only javascript and html,  we can get data from input box. using
document.getElementById('web').value
where, web = id of the input text box.

Sample code that use javascript to get input value:

[Note : Paste this code inside the <body> tag. to work.]

<script type="text/javascript">
function visit()
{
    var t = document.getElementById('web').value ;
    alert( t );
   
}
</script>

Enter Web Address: <input type="text" name="web" id="web"/>
<input type="button" value="Show what is in this Text Box" onclick='show();'/>


(If you found this article useful then share with your friends.)

How to use PHP bot to get Wikipedia definitions

php
This code helps to parse wikipedia definitions on given keyword.
Here is a code given that parse webpage using php with Curl extension.
A function is given which takes the keyword as input and outputs the array which holds the data.
$url : Holds the link to be parsed.

File name : wiki_parse.php
<?php
//FUNCTION THAT :PARAMETER - KEYWORD , AND RETURNS WIKI DEFINITION (IN ARRAY FORMAT)
function wikidefinition($s) {
//ENGLISH WIKI
    $url = "http://en.wikipedia.org/w/api.php?action=opensearch&search=".urlencode($s)."&format=xml&limit=1";
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
    curl_setopt($ch, CURLOPT_POST, FALSE);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_NOBODY, FALSE);
    curl_setopt($ch, CURLOPT_VERBOSE, FALSE);
    curl_setopt($ch, CURLOPT_REFERER, "");
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    curl_setopt($ch, CURLOPT_MAXREDIRS, 4);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; he; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8");
   
    $page = curl_exec($ch);
    $xml = simplexml_load_string($page);
    if((string)$xml->Section->Item->Description) {
        return array((string)$xml->Section->Item->Text,
                     (string)$xml->Section->Item->Description,
                     (string)$xml->Section->Item->Url);
    } else {
        return "";
    }
}
//END OF FUNCTION WIKIDEFINITIONS



//USE OF FUNCTION
$data = wikidefinition('Bangladesh') ;
//var_dump( wikidefinition('bangladesh') ) ; //displays the array content
echo "Word:"       . $data[0] . "<br/>";
echo "Definition:" . $data[1]  . "<br/>";
echo "Link:"       . $data[2] . "<br/>";

?>

Thanks to barattalo.it

(If you found this article useful then share with your friends.)