JavaScript

  • Open window with information (AJAX WAY)

    In this example we will execute AJAX that will return data which will be visualised in new window (tab). $(document).on(“click”, “.sysnav”, function(){ //On clicked button id=$(this).attr(‘id’); //Command that will be executed in script.php $.ajax({ url:’script.php’, type:’POST’, data:{ command:id } }).done(function(data){ var target = window.open(“/admin.php”); //Open new window target.NavigationPopup = data; //Data to be loaded…

  • Load jQuery if not loaded (Asynchronous Way)

    If you load scripts through ajax and they won’t execute. After that place your code that you want to run.

  • Display A Popup Only Once Per User

    HTML: Присъединете се към нас в социалната мрежа JOIN US jQuery code: jQuery(document).ready(function(){ if(localStorage.getItem(‘popState’) != ‘shown’){ jQuery(‘#wrap-banner’).css({ ‘display’:’block’ }); localStorage.setItem(‘popState’,’shown’) } jQuery(‘#close-offer’).click(function(){ jQuery(‘#wrap-banner’).hide(); }); });

  • Simple jQuery image/banner changer

    This is simple image slider that change images/banners with fade effect in declared interval. HTML:

  • How to create simple parallax effect.

    It is really simple to create parallax effect on your site. Add this script to your html head. In your body tag add -> onload=”onLoad()”. This will automatically start the script on page load. Here is some css you will need for example to work: body{background: url(“/image/bg-texture-1200.png”) repeat-x top center; width: 100%; background-color: #E9F5FA;…

  • Passing values in JS in objects is by reference

    Passing in a primitive type variable like a string or a number, the value is passed in by value. Passing in an object, however, passes it in by reference. Here is an example:

  • What is this (IIFE) construct in javascript?

    Immediately-Invoked Function Expression, or shorter: IIFE. It executes immediately after it’s created. This pattern is often used when trying to avoid polluting the global namespace, because all the variables used in the function are not visible outside its scope. It’s good to use when we have multiple functions with the same name. The output…

  • Activate script after scrolling

    Example of script that activates after scrolling to the end of site.

  • Read the GET variables in url (JQuery)

    How to get the GET variable from URL with jQuery var split = location.search.replace(‘?’, ”).split(‘&’).map(function(val){ return val.split(‘=’); }); Now it is saved in array named – split. You can easily access variable name by split[index][0] and value by split[index][1].