Displaying 1-10 of 10 results.
Wiki: Loads a JavaScript file asynchronously with a callback, like jQuery's $.getScript() except without jQuerywiki
posted by admin on April 13, 2017

function j(u, c) {
var h = document.getElementsByTagName('head')[0], s = document.createElement('script');
s.async = true; s.src = u;
s.onload = s.onreadystatechange = function () {
if (!s.readyState || /loaded|complete/.test(s.readyState)) {
s.onload = s.onreadystatechange = null; if (h && s.parentNode) { h.removeChild(s) } s = undefined;
if (c) { c() }
}
};
h.insertBefore(s, h.firstChild);
}
Read more
Wiki: How to make an AJAX call without jQuery with GET and POST?wiki
posted by admin on March 27, 2017
Using the following snippet you can do similar things pretty easily, like this:

ajax.get('/test.php', {foo: 'bar'}, function() {});

Here is the snippet:

var ajax = {};
ajax.x = function () {
if (typeof XMLHttpRequest !== 'undefined') {
return new XMLHttpRequest();
}
var versions = [
"MSXML2.XmlHttp.6.0",
"MSXML2.XmlHttp.5.0",
"MSXML2.XmlHttp.4.0",
"MSXML2.XmlHttp.3.0",
"MSXML2.XmlHttp.2.0",
"Microsoft.XmlHttp"
];

var xhr;
for (var i = 0; i < versions.length; i++) {
try {
xhr = new ActiveXObject(versions[i]);
break;
} catch (e) {
}
}
return xhr;
};

ajax.send = function (url, callback, method, data, async) {
if (async === undefined) {
async = true;
}
var x = ajax.x();
x.open(method, url, async);
x.onreadystatechange = function () {
if (x.readyState == 4) {
callback(x.responseText)
}
};
if (method == 'POST') {
x.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
}
x.send(data)
};

ajax.get = function (url, data, callback, async) {
var query = [];
for (var key in data) {
query.push(encodeURIComponent(key) + '=' + encodeURIComponent(data[key]));
}
ajax.send(url + (query.length ? '?' + query.join('&') : ''), callback, 'GET', null, async)
};

ajax.post = function (url, data, callback, async) {
var query = [];
for (var key in data) {
query.push(encodeURIComponent(key) + '=' + encodeURIComponent(data[key]));
}
ajax.send(url, callback, 'POST', query.join('&'), async)
};
Read more
Resolved: Javascript jSnow plugin Uncaught TypeError: Cannot read property 'msie' of undefined
posted by admin on December 19, 2016
I use jsnow.js javascript plugin and now I have got this error.

$(document).ready(function () {
$().jSnow({zIndex : 999999999});
})

Please help to resolve itRead more
Resolved: Javascript body onclick function event
posted by admin on December 15, 2016
I have a function and onmousemove event in body attribute.
JS

function mouseShowHandler(e){

e = e || window.event


if (e.pageX == null && e.clientX != null ) {

var html = document.documentElement

var body = document.body

e.pageX = e.clientX + (html && html.scrollLeft || body && body.scrollLeft || 0) - (html.clientLeft || 0)

e.pageY = e.clientY + (html && html.scrollTop || body && body.scrollTop || 0) - (html.clientTop || 0)



}
xx=e.pageX
yy=e.pageY
}


HTML

...
<body onmousemove="mouseShowHandler(event)">
...

It is working fine, But I want to event handler to my script file, and remove from bodyRead more
Resolved: Copy textarea text to the clipboard in JavaScript?
posted by admin on August 26, 2016
What is the best way to copy text to the clipboard? (multi-browser)
Like CTRL + CRead more
Resolved: Replace %2C with a comma in javascript?
posted by admin on June 18, 2016
I get string from URL

#&q=car&category=Car%20Audio%2CAccessories&brand=

%2C is comma in url, and I want to recover my string with comma

#&q=car&category=Car%20Audio,Accessories&brand=
Read more
Resolved: Submit form on change of dropdown list
posted by admin on April 26, 2016
I have SELECT dropdown list

<form method="GET" >
<select id="id_period" name="period">
<option value="day">day</option>
<option value="week">week</option>
<option value="month">month</option>
<option value="all" selected="selected">all time</option>
</select>
</form>

I want to submit form on changeRead more
Resolved: JavaScript replace or remove words from string using one function
posted by admin on April 23, 2016
I have string and I want to replace or remove words combination. Not one by one, not using

str = str.replace("green", "red");
str = str.replace("blue", "red")
etc...


I want something like

str.function("words combination", "red")
Read more
Resolved: What does “javascript:void(0)” mean?
posted by admin on April 12, 2016

<a href="javascript:void(0)" id="loginlink">login</a>


I've seen such hrefs many times, but I don't know what exactly that means.Read more
Resolved: JavaScript get last characters from string. Get file extension from filename
posted by admin on April 9, 2016
I have file name, like
dad a d as da a d ad as d as d.jpg

I want to get file extension , the last three letters.Read more