Please wait while loading...

Read more Allow multiple line of code for a string variable in Javascript

When we set a html string to a variable, we cannot come to next line with only press enter like in php, example below show the case:

$htm = '';

You will get a warning like this:
SyntaxError: unterminated string literal

Usually, we will use "+" to link up multiple line of code to solve this problem. Today I found a way to allow this which just easily add a "\" at the end of a line.

$htm = '';

Read more Detect browser support HTML5 drag and drop by javascript

if('draggable' in document.createElement('span')) {
  alert("Drag support detected");

Read more A fix for the iOS orientationchange zoom bug

Place the following javscript in your document head.

if (navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i)) {
/*! A fix for the iOS orientationchange zoom bug. Script by @scottjehl, rebound by @wilto.MIT / GPLv2 License.*/(function(a){function m(){d.setAttribute("content",g),h=!0}function n(){d.setAttribute("content",f),h=!1}function o(b){l=b.accelerationIncludingGravity,i=Math.abs(l.x),j=Math.abs(l.y),k=Math.abs(l.z),(!a.orientation||a.orientation===180)&&(i>7||(k>6&&j<8||k<8&&j>6)&&i>5)?h&&n():h||m()}var b=navigator.userAgent;if(!(/iPhone|iPad|iPod/.test(navigator.platform)&&/OS [1-5]_[0-9_]* like Mac OS X/i.test(b)&&b.indexOf("AppleWebKit")>-1))return;var c=a.document;if(!c.querySelector)return;var d=c.querySelector("meta[name=viewport]"),e=d&&d.getAttribute("content"),f=e+",maximum-scale=1",g=e+",maximum-scale=10",h=!0,i,j,k,l;if(!d)return;a.addEventListener("orientationchange",m,!1),a.addEventListener("devicemotion",o,!1)})(this);

Read more Call parent window from iframe

Today learn a new function  --- window.parent.

Although iframe is less useful nowadays, we still on some situation, such as ajax upload. Using window.parent, you can call a function on the main frame from the iframe, this to make interaction of the parent window and the iframe window. You can try and find the use in the following example: