For smart Primates & ROBOTS (oh and ALIENS ).

Showing posts with label html. Show all posts
Showing posts with label html. Show all posts

Monday, April 15, 2024

Add Dependent Scripts

 

 here is the code that allow to add dependent script :

 

 

    <script>
        const addDependentScripts = async function( scriptsToAdd ) {
        const s=document.createElement('script')
        for ( var i = 0; i < scriptsToAdd.length; i++ ) {
            let r = await fetch( scriptsToAdd[i] )
            s.text += await r.text()
        }
        document.querySelector('body').appendChild(s)
        }
         </script> 


Uses as below :

       <script>

    try {
        addDependentScripts( [
            "https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js",
            "https://cdn.mywebshopapp.com/test/a1.js",
            "https://cdn.mywebshopapp.com/test/a2.js",
            "https://cdn.mywebshopapp.com/test/a3.js",
            "https://cdn.mywebshopapp.com/test/a4.js"
        ] );
        }
        catch (err) { }

       </script>

Share:

Thursday, January 25, 2024

Define own custom HTML element

 Define own custom HTML element


Here I am demonstrating how to define your own custom HTML element or control and how to use it.

Define is as <my-test-element-one> </my-test-element-one>
and then use my JavaScript. The complete code it below:

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Hello!</title>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
  </head>
  <body>
<my-test-element-one>
</my-test-element-one>
<script>
class my_test_element_one extends HTMLElement{
  connectedCallback(){
    this.innerHTML=`  <div class="myclass" style=" width:600px;height:500px; background-color:green">
            <img src="https://images.pexels.com/photos/267415/pexels-photo-267415.jpeg?auto=compress&cs=tinysrgb&w=300" />
    </div>`
  }
}
customElements.define('my-test-element-one', my_test_element_one);
</script>
</body>
</html>

 

 

Share:

Friday, January 20, 2023

How to add inline javascript using createElement

How to add inline javascript using createElement

Here  are the 2 examples of codes.

Code 1:

<script>
var scriptNode          = document.createElement ("script");
scriptNode.textContent  = "alert('aaa');";
document.head.appendChild (scriptNode);
</script>


Code 2:

<script>
var scriptNode=document.createElement("script");
scriptNode.textContent= "!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,document,'script','https://connect.facebook.net/en_US/fbevents.js');fbq('init',  'mynumber' );fbq('track', 'PageView', {customer_groups: 'Visitatore',default_customer_group: ''});";
document.head.appendChild (scriptNode);
</script>
 

 

 

 

Share:

Thursday, January 19, 2023

pass and get data in createElement statement in javascript

How to pass and get data in createElement statement in javascript?

Here is the listed below code:

In "a1.html"
<script>
var myscript= document.createElement('script');
myscript.setAttribute('data-id1','fordata1');
myscript.setAttribute('data-id2','fordata2');
myscript.setAttribute('data-id3','fordata3');
myscript.setAttribute('data-id4','fordata4');
myscript.setAttribute('data-id5','fordata5');
myscript.setAttribute('src','get-id-in-js.js');
document.head.appendChild(myscript);
</script>

 

 In "get-id-in-js.js" file

var scripts=document.getElementsByTagName("script");
console.log(scripts[0].getAttribute("data-id1"));
console.log(scripts[0].getAttribute("data-id2"));
console.log(scripts[0].getAttribute("data-id3"));
console.log(scripts[0].getAttribute("data-id4"));
console.log(scripts[0].getAttribute("data-id5"));


 

 

 

Share:

pass and get data in script tag in javascript

How to pass and get data in script tag in javascript Here is the code: 

In "a1.html"

<script async="" data-id1="fordata1" data-id2="fordata2" data-id3="fordata3" data-id4="fordata4" data-id5="fordata5" src="get-id-in-js.js"></script>
 

 In "get-id-in-js.js" file: 

var scripts=document.getElementsByTagName("script");console.log(scripts[0].getAttribute("data-id1")); console.log(scripts[0].getAttribute("data-id2")); console.log(scripts[0].getAttribute("data-id3")); console.log(scripts[0].getAttribute("data-id4")); console.log(scripts[0].getAttribute("data-id5")); 

 

 

 

Share:

Thursday, January 12, 2017

load images using JavaScript

Another way to load images using JavaScript

When you write code in JavaScriputer system.
Below is the another way to load images from JavaScript code.

<img src="data:image/png;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=" data-src="http://www.mysite.com/media/t1.png">
 
function initS() {
    var myimg = document.getElementsByTagName('img');
    for (var i=0; i<myimg.length; i++) {
        if(myimg[i].getAttribute('data-src')) {
            myimg[i].setAttribute('src',myimg[i].getAttribute('data-src'));
        }
    }
}
setTimeout("initS();", 20000);
</script> 



connect On of OFF.
Share:

Saturday, January 07, 2017

Load mp4 file

How to load .mp4


below is few lines of code:

<video width="640" height="480" controls>
  <source src="4.mp4" type="video/mp4">
   Your browser does not support the video tag.
</video>




Share:

Another way to load JavaScript


Another way to load JavaScript

There are another way to load Javascript file in any page. use below code to load Js file.

<script type="text/javascript">
function dhtml5() {
var eh= document.createElement("script");
eh.src = "a1.js";
document.body.appendChild(eh);
}
setTimeout("dhtml5();",8000);
</script>


Share:

Tuesday, May 31, 2016

How to check if internet active in your computer

How to check if internet active in your computer

When you write code in JavaScript sometime you code does not execute due to loss of internet connectivity.  so how you check if internet connection properly ON in your computer system.
below is one line of JavaScript code that check your system internet connect On of OFF.

Code is:
var isonline = navigator.onLine;
Share:

Sunday, February 28, 2016

delete multiple emails in Gmail basic HTML mode


How to delete multiple emails in Gmail basic HTML mode

Sometime you have slow internet connect, so at that time you will not able to open gmail in standard mode. at that time you will open it in HTML mode.
It is okay. now when you want to delete multiple emails(100 emails at a time) then you need to click checkbox one by one. this will take many times and frustration.
here is the solution for this types of situation. see below image and follow instructions.
.















Share:

Thursday, May 28, 2015

How to fix any HTML tag at any position

Problem:

How to fix any HTML tag at any position for ex: fix a div at right bottom corner?

Solution:

Use style z-index, bottom, right attribute

Example:

<div id="loading_msg" style="position: fixed; z-index: 99;  bottom: 15px; right: 10px;
    display:; background-color:#CC99FF">Loading now Please wait...</div>
Share:

Thursday, April 23, 2015

html html5 to Pdf

Generate PDF file of html html5 with div span tags. It really works on liquid layout also!
Try it now!





html html5 to Pdf
Download here:

Part-1 
Part-2
Part-3
Part-4
Part-5
Part-6
Part-7
Part-8
Part-9
Part-10
Part-11

Extract  all files Part-1 to Part-11 and paste all files in one folder and double click on
Html-Html5-to-PDF.exe
Share:

Friday, April 17, 2015

jquery ui datepicker automatically delete text from input field

Problem:

Did you worked with jquery ui date picker? when assigned a default value to text filed, jquery ui datepicker will automatically delete text from that textbox field. So how to stop it?

Solution:

It seems the bug in jquery ui datepicker which is automatically delete text from input field. to overcome this problem you need to write 22 lines of code as example below:

Example:

// assume that the $edit_diesel_date is already filled with date value.
// write this code very bootom of your page.
function dook() {  $("#diesel_date").val("<?php echo $edit_diesel_date;?>");     }
setTimeout("dook();", 500);
Share:

Wednesday, March 18, 2015

Change Search in This Blog size

Problem:

If you have a blog owner in blogger and used the "Search in This Blog" widget, you can see this size is very large and taking lot of spaces in your blog

Solution:



Use below code at the end of your blogger XML file

<script>
function r_search() {
var r_place_s=&quot;h2&quot;;
var r_place_t=&quot;h5&quot;;
var Attribution1=document.getElementById(&quot;CustomSearch1&quot;);
var Attribution1_html=Attribution1.innerHTML;
var regex = new RegExp( &#39;(&#39; + r_place_s + &#39;)&#39;, &#39;gi&#39; );
Attribution1.innerHTML=Attribution1_html.replace( regex, r_place_t );
}
r_search();
</script>

Share:

Friday, March 13, 2015

Gauge chart in Google Chart

How to implement Google Gauge chart. The most important things is that how to change it's needle alternate with some interval. I have made the code that will change Gauge Google Chart's needle alternate interval.


Gauge chart in Google Chart











EXAMPLE - 1
--------------------

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!--
How to use Gauge chart and how to change needle frequently interval.
if this code is now show the chart then remove above two lines of <!DOCTYPE tag and <html tag and use listed below tags:
1- <html>  2- <head>
-->
  <head>
    <script type='text/javascript' src='https://www.google.com/jsapi'></script>
    <script type='text/javascript'>
      google.load('visualization', '1', {packages: ['gauge']});
    </script>
    <script type="text/javascript">
    var gauge;
    var gaugeData;
    var gaugeOptions;
    function drawGauge() {
      gaugeData = google.visualization.arrayToDataTable([['Engine', 'Torpedo'], [120, 80]]);
      gauge = new google.visualization.Gauge(document.getElementById('gauge'));
      gaugeOptions = {
          min: 0,
          max: 280,
          yellowFrom: 200,
          yellowTo: 250,
          redFrom: 250,
          redTo: 280,
          minorTicks: 5
      };
      gauge.draw(gaugeData, gaugeOptions);
    }
      function changeTemp(dir) {
        //gaugeData.setValue(0, 0, gaugeData.getValue(0, 0) + dir * 25);
      //gaugeData.setValue(0, 1, gaugeData.getValue(0, 1) + dir * 20);
      gaugeData.setValue(0, 0, Math.floor((Math.random()*100)+1));
      gaugeData.setValue(0, 1, Math.floor((Math.random()*100)+1));
      gauge.draw(gaugeData, gaugeOptions);
    }
      setInterval("changeTemp(1);",1000);
    google.setOnLoadCallback(drawGauge);
    </script>
  </head>
  <body style="font-family: Arial;border: 0 none;">
    <div id="gauge" style="width: 300px; height: 300px;"></div>
  </body>

</html>



EXAMPLE - 2

--------------------
<html>
  <head>
    <script type='text/javascript' src='https://www.google.com/jsapi'></script>
    <script type='text/javascript'>
      google.load('visualization', '1', {packages:['gauge']});
      google.setOnLoadCallback(drawChart);
    
      function drawChart() {
      setInterval("docharts();",4000);
      }

 function docharts(){
var data = google.visualization.arrayToDataTable([
          ['Label', 'Value'],
          ['Memory', Math.floor((Math.random()*100)+1) ],
          ['CPU', Math.floor((Math.random()*100)+1) ],
          ['Network', Math.floor((Math.random()*100)+1)]
        ]);

        var options = {
          width: 400, height: 120,
          redFrom: 90, redTo: 100,
          yellowFrom:75, yellowTo: 90,
          minorTicks: 5,
 animation:{
        duration: 5000
      }
        };
        var chart = new google.visualization.Gauge(document.getElementById('chart_div'));
        chart.draw(data, options);
 }
    </script>
  </head>
  <body>
    <div id='chart_div'></div>
  </body>

</html>
Share:

Wednesday, March 11, 2015

HOW TO REMOVE BLOGGER WORD IN BLOG

Problem:

If you have a blog in blogger. then you can see "blogger" word at the bottom of page or any where in the blog. if you don't need this then how can you remove this?

Solution:

You just need copy and past listed below code at the end of blog.

Example:

<script type='text/javascript'>
function r_p() {
var r_place_s=&quot;Blogger&quot;;
var r_place_t=&quot;Galaxy Code&quot;;
var Attribution1=document.getElementById(&quot;Attribution1&quot;);
var Attribution1_html=Attribution1.innerHTML;
var regex = new RegExp( &#39;(&#39; + r_place_s + &#39;)&#39;, &#39;gi&#39; );
Attribution1.innerHTML=Attribution1_html.replace( regex, r_place_t );
}
Share:

Friday, November 07, 2014

get selected text of select from jquery

Problem:
How to get selected text of select from jquery?

While working in web programming sometime you need to get text from select box or combobox along with it's value.

Solution:
You will use .val() method to get value and use .text() method to get text from select box or combo box in jquery.



Example:
Use listed below code:
To get value:
var myval=$("#myselect").val();

To get Text:
var mytxt=$("#myselect :selected").text();
Share:

Sunday, September 21, 2014

Thin border table in html

How to create Thin border table in html:
Use following html code to create Thin border table in html.


<table cellspacing="0" cellpadding="1" style="border-color:Black;border-width:1px;border-style:Solid;height:108px;width:100%;border-collapse:collapse;" rules="all" >
  <tbody>
    <tr >
      <th scope="col">Date</th>
      <th scope="col">Time</th>
      <th scope="col">Status at</th>
      <th scope="col">Status</th>
    </tr>
    <tr>
      <td align="center">25/08/2014</td>
      <td align="center">10:20:15</td>
      <td align="left">Status A</td>
      <td align="left">Status B</td>
    </tr>
  </tbody>
</table>

Share:

Thursday, August 14, 2014

Rotate any Div in jquery

Rotate any Div in html jquery.
==========================



<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <title>Multirotation test</title>
        <script type="text/javascript" src="../js/jquery-1.6.js"></script>
        <script type="text/javascript" src="jquery.multirotation-1.0.js"></script>
    </head>
    <style type="text/css">
        div{text-align:center;margin:auto}
        div.rotable{background:#00CC66;border:solid 2px #f00;color:#fff;width:10px;height:10px;padding:5px;margin-top:60px;margin-bottom:60px}
    </style>
    <body>
        <div><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
           <div id="img_test" class="rotable">Amit
               
            </div>
            <p id="degs"></p>
        </div>
    </body>
      <script type="text/javascript">
        function plus(id) {
            $(id).rotate({ angle: 10 });
            get(id);
            return false;
        }

        function minus(id) {
            $(id).rotate({ angle: 90, direction: false });
            get(id);
            return false;
        }

        function reset(id) {
            $(id).clearRotation();
            get(id);
            return false;
        }

        function get(id) {
            var degs = $(id).getCurrentDegrees();
            //$('p#degs').html("Current degs: <b>" + degs + "°</b>");
        }
        var ang=1;
        intervalID=setInterval("setRotate('#img_test');",100);
       
        function setRotate(id) {
            $(id).rotate({ angle: 5 });
            get(id);
        }
       
       
    </script>
</html>



HERE IS THE jquery.multirotation-1.0.js CODE:
-----------------------------------------------------------------------

(function($){
    //global array to save the current rotation of the elements
    $.elems_rotation_history = [];

    $.fn.extend({
        clearRotation: function() {
            return this.each(function() {
                //get the element's identifier
                var id = this.id;
                //remove element from array
                $.elems_rotation_history[id] = null;
            });
        },

        getCurrentDegrees: function() {
            var id = this.attr('id');
            if (!$.elems_rotation_history[id]) {
                return 0;
            }
            return degs = $.elems_rotation_history[id].rotation;
        },

        rotate: function(options) {
            //create console
            if (!window.console) console = {};
            console.log = console.log || function(){};
            console.warn = console.warn || function(){};
            console.error = console.error || function(){};

            //set the default values
            var defaults = {
                  angle: 0
                , direction: true
                , speed: 0
                , deg2radians: Math.PI * 2 / 360
                ///debug
                , debug: false
                ///end
            };

            //to access options values use this: options.option_name
            var options = $.extend(defaults, options);

            return this.each(function() {
                //get the element's identifier
                var id = this.id;

                //if there aren't elements and there isn't the element into the array, sets rotation to 0
                if ($.elems_rotation_history && !$.elems_rotation_history[id]) {
                    $.elems_rotation_history[id] = { rotation: 0 };
                }

                //sets the rotation direction
                if (!options.direction) {
                    options.angle = options.angle * (-1);
                }

                //increments angle rotation of the element
                $.elems_rotation_history[id].rotation = (parseInt($.elems_rotation_history[id].rotation) + options.angle) % 360;

                ///debug
                if (options.debug) {
                    console.log("Angle = " + $.elems_rotation_history[id].rotation + " degree");
                }
                ///end

                rad = $.elems_rotation_history[id].rotation * options.deg2radians;
                costheta = Math.cos(rad);
                sintheta = Math.sin(rad);

                var a = parseFloat(costheta).toFixed(8);
                var b = parseFloat(sintheta).toFixed(8);
                var c = parseFloat(-sintheta).toFixed(8);
                var d = parseFloat(costheta).toFixed(8);

                var sMatrix = "matrix(" + a + ", " + b + ", " + c + ", " + d + ", 0, 0)";

                if ($(this).get(0).filters) {
                    if (options.speed > 0) {
                        console.warn("You set the speed options but IE doesn't support CSS3 transitions");
                    }

                    //if the browser is IE
                    try {
                        var x = $(this).get(0).filters.item("DXImageTransform.Microsoft.Matrix").enabled;
                    }
                    catch(e) {
                        $(this).get(0).style.filter += "progid:DXImageTransform.Microsoft.Matrix(sizingMethod='auto expand');";
                    }

                    var matrix = $(this).get(0).filters.item("DXImageTransform.Microsoft.Matrix");
                    matrix.M11 = costheta;
                    matrix.M21 = sintheta;
                    matrix.M12 = -sintheta;
                    matrix.M22 = costheta;
                    matrix.enabled = true;

                    ///debug
                    if (options.debug) {
                        console.log("Set transform = matrix[" + matrix.M11 + ", " + matrix.M21 + ", " + matrix.M12 + ", " + matrix.M22 + "]");
                    }
                    ///end
                } else {
                    //animate rotation if speed > 0s
                    if (options.speed > 0) {
                        $(this).css("-moz-transition", "all " + options.speed + "s ease-in-out");
                        $(this).css("-webkit-transition", "all " + options.speed + "s ease-in-out");
                        $(this).css("-o-transition", "all " + options.speed + "s ease-in-out");
                    }
                    $(this).css("-moz-transform", sMatrix);
                    $(this).css("-webkit-transform", sMatrix);
                    $(this).css("-o-transform", sMatrix);

                    ///debug
                    if (options.debug) {
                        console.log("Set transform = " + sMatrix);
                    }
                    ///end
                }
            });
        }
    });
})(jQuery)

Share:

Friday, July 11, 2014

Add html tag dynamically in html

Add html tag dynamically in html

<script src="jquery-2.1.1.js" language="javascript" type="application/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {
        var ID = 1;
        function addRow() {
            var html =  '<tr>' +
                        '<td>Name: <input type="text" name="aa' + ID + '" /></td>' +
                        '<td>File: <input type="file" name="fileUpload' + ID + '" /></td>' +
                        '<td><input type="button" class="BtnPlus" value="+" /></td>' +
                        '<td><input type="button" class="BtnMinus" value="-" /></td>' +
                        '</tr>'
            $(html).appendTo($("#Table1"))
            ID++;
        };
        $("#Table1").on("click", ".BtnPlus", addRow);
        function deleteRow() {
            if(ID==1) return;
            var par = $(this).parent().parent();
            par.remove();
            ID--;
        };
        $("#Table1").on("click", ".BtnMinus", deleteRow);
    });
</script>
<table id="Table1" cellspacing="3">
    <tr>
        <td>Name: <input type="text" name="aa0"  id="aa0" /></td>
        <td>File: <input type="file" name="fileUpload0"/></td>
        <td><input type="button" class="BtnPlus" value="+" /></td>
        <td><input type="button" class="BtnMinus" value="-" /></td>
    </tr>
</table>
Share:

Ads Inside Post

Powered by Blogger.

Archive