Saturday, January 22, 2022

How to Use Javascript Function






 step 1: open link dilsecodie.

 step 2 : Javascript section Splitword Function Using Javascript.

step 3: copy code from the website 

step 4 : use in any Js function

step 5: only pass the word, need as a split result, dynamically 

step 6 : get the return from the function 


Now how to check cookies in javascript .

var cookies = document.cookie ? document.cookie.split('; ') : [];

var rdecode = /(%[0-9A-Z]{2})+/g; var i = 0 for (; i < cookies.length; i++) {

var parts = cookies[i].split('=');

var cookie = parts.slice(1).join('=');

          if (cookie.charAt(0) === '"') {cookie = cookie.slice(1, -1);}

Using this piece of code in your project you will get cookie status in your project .

Like doing validation of form  if you want to validate any HTML form we can do it using javascript function  .

function validateForm() { 

    var x = document.forms["myform1"]["demo"].value;

    if(x==null || x ==''){ 

    }else{

    $("#loader").show(); --- its a custom way to show some msg or loader at user end.

    return true; -- checking for status 

    }

}


Now lets see inner HTML example bcoz its required every where when using javascript ,

var ele = document.getElementById(id);

if(ele.style.display == "block") {       

    ele.style.display = "none";

    document.getElementById("header").innerHTML = "Dilsecodie Search";

    document.getElementById("search").value = "dilsecodie blog";

   

}else{ 

ele.style.display = "block"; 

document.getElementById("header").innerHTML = "dilsecodieSearch";

                        document.getElementById("search").value ="dilsecodie";

}  

as we can see javascript is a way we can use innerHTML to set or provide any values to particular elements by using id ,

as you can also see in the example we can also reset the style property for that element by using its id.

Now let's assume how to create an HTML page using javascript.

Create a new HTML document.


var writehtmlDoc = writehtml[0].contentWindow ? writehtml[0].contentWindow :

 writehtml[0].contentDocument.document ? writehtml[0].contentDocument.document : 

writehtml[0].contentDocument;

        writehtmlDoc .document.open();

      writehtmlDoc .document.write('<html><head><title>DIV Contents</title>');

        var htmlToPrint = '' +

        '<style type="text/css">' +

        '.table3 th, .table3 td {' +

        'border:1px solid #000;' +

        'padding:0.5em;' +

        '}' +

        '</style>';

        writehtmlDoc .document.write('</head>');

        writehtmlDoc .document.write(htmlToPrint);

        writehtmlDoc.document.write('<body>');

        writehtmlDoc.document.write(contents);

        writehtmlDoc.document.write('</body></html>');

        writehtmlDoc.document.close();

        setTimeout(function () {  window.frames["writehtml"].focus();

            window.frames["writehtml"].print();--- some custom function

            writehtml.remove();

        }, 600);


From the above  example, we can see how  we can create every HTML document, 

first created headers for page, as you can also see how div created you can create n numbers

of div according to your page design, these types of pages are also used for cloning for pages using

javascript code.


Now let's see some important functions of javascript .

 how to make page open in new window 

function makenewwindow(){  - this function  used to make new window with output page

var strwidth=window.outerWidth-650; -- to set width of a page.

var strheight=(window.outerHeight-160); --- need to set your height of page as per requirement .

var leftStr = (screen.width-window.outerWidth)/2; -- its calculate left side window

var topStr = (screen.height-window.outerHeight)/2-100;--- its give total of top height 

 window.open("yourpageurl.php",---- this important to provide your page name to open with

'newWin',"chrome=yes, minimizable=no,width="+strwidth+",-- we can provide info for chrome flag

left="+leftStr+",top="+topStr

 fullscreen=yes, resizable=no, 

alwaysraised=yes, scrollbars=yes, 

menubar=no, toolbar=no, titlebar=no, statusbar=no, 

location=no, directories=no); }

As per the above logic, we can create a window as a new tab.  and can set data according to as per our needs.







No comments:

Post a Comment