In JavaScript, as in many other programming languages, variables have a scope – global or local / block. Functions also have a scope, if they
Read moreAdjusting PHP pages to work with full caching
Caching web pages speeds-up dramatically the loading time. A ready, waiting cached version is served, no load on the server, no preparation, here it is!
Read moreGetting an entire HTML code of an element using element’s ID and outerHTML property
I needed a way to send an email to my site’s visitors with info already generated on screen. In my case it was a dynamically
Read moreTracking protection and JavaScript errors
A few days ago I noticed redirect issues on one of our websites. Instead of opening a new window with a download form (with window.open
Read morePrint object content in JavaScript using an “alert”
A highly readable, indented output using:
1 |
alert(JSON.stringify(OBJECT_TO_OUTPUT, null, 5)); |
Read more
Effects – Animate On Scroll (AOS), ColorBox, Responsive Tabs
A great library for animating object appearance when scrolling to them: https://github.com/michalsnik/aos Important note – if the page has changed in its length (i.e. opening/closing
Read moreStopping YouTube video when closing an overlay (modal/popup)
Sometime you want your videos to open in a nice overlay instead of a new window. There are many solutions for that (modals in BootStrap,
Read moreReady function in JavaScript
jQuery users are happy, they have:
1 |
$( document ).ready |
If you wish to have a vanilla JavaScript solution, this is the one I’m using:
Read moreAdjusting an iframe height automatically according to its content
I would always prefer to avoid using an iframe, but sometimes it is the easy / only way out of a technical mess. If the
Read morePrevent default action from being triggered (form submission prevention or link popups)
When there’s a link that should open a window or do something different than it’s default behavior it’s best to add the javascript in an
Read moreGoogle chrome developer tools – searching in all sources (local sources)
In order to search in all local sources (html,js) open the developers tools (F12), press Ctrl+Shift+F and search for whatever you need. Note that there
Read moreDelete Remove Unbind Turn-off attached event with jQuery
Adding the event:
1 |
$("body").mouseleave(showPop); |
Removing the event:
1 |
$("body").off("mouseleave"); |
Event when mouse is leaving the browser screen
1 |
$("body").mouseleave(showPop); |
Seems to work with all browsers. User tries to use the toolbar or exit the page – kaboom, we have a message.
Read moreForcing CSS / Javascript refresh – avoiding caching
When including the CSS or JavaScript files add a parameter to the end of the file:
1 |
<link rel="stylesheet" type="text/css" href="style.css?version=4122005" /> |
If there’s a need to force refresh constantly
Read moreCreating and deleting form fields dynamically
I needed a form that allows the user to add and remove products with quantities as he wishes. The form had one row with a
Read morejQuery animate easing parameter
While trying to create animations with jQuery I noticed that there are short delays between each couple of animations. After reading on the subject it
Read moreAccessing database data with jQuery using a PHP proxy and avoiding the 404 error
I needed to pull database records into a page but couldn’t use PHP directly on that page (it was limited by the CMS used). So
Read moreSelecting text by clicking on a button
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
<div id=”mails” style=”margin-top:80px”> <button name=”copy” title=”Select” >Select all</button><br/><br/> <script> jQuery.fn.selectText = function(){ var doc = document; var element = this[0]; console.log(this, element); if (doc.body.createTextRange) { var range = document.body.createTextRange(); range.moveToElementText(element); range.select(); } else if (window.getSelection) { var selection = window.getSelection(); var range = document.createRange(); range.selectNodeContents(element); selection.removeAllRanges(); selection.addRange(range); } }; $(document).ready(function(){ $(“button”).click(function(){ $(“#mails”).selectText(); }); }); </script> |
Read more