Inspecting what facebook is doing in my navigator, I see this code:
for (;;);{"t":"refresh"}
If you try to evaluate it, you can figure what happens (infinite loop).
Do you Know what it is?
I recently posted a detailed description of the issue I am facing here at SO. As I couldn't send an actual $http request, I used timeout to simulate asynchronous behavior. Data binding from my model to view is working correct, with the help of @Gloppy
Now, when I use $http instead of $timeout (tested locally), I could see the asynchronous request was successful and data is filled with json response in my service. But, my view is not updating.
updated Plunkr here
I'm loading several external JSON files and want to check if they have been successfully cached before the the next screen is displayed. My strategy is to check the name of the array to see if it an object. My code works perfectly when I check only a single array and hard code the array name into my function. My question is: how can i make this dynamic?
not dynamic: (this works)
$("document").ready(){
checkJSON("nav_items");
}
function checkJSON(){
if(typeof nav_items == "object"){
// success...
}
}
dynamic: (this doesn't work)
$("document").ready(){
checkJSON("nav_items");
checkJSON("foo_items");
checkJSON("bar_items");
}
function checkJSON(item){
if(typeof item == "object"){
// success...
}
}
here is the a larger context of my code:
var loadAttempts = 0;
var reloadTimer = false;
$("document").ready(){
checkJSON("nav_items");
}
function checkJSON(item){
loadAttempts++;
//if nav_items exists
if(typeof nav_items == "object"){
//if a timer is running, kill it
if(reloadTimer != false){
clearInterval(reloadTimer);
reloadTimer = false;
}
console.log("found!!");
console.log(nav_items[1]);
loadAttempts = 0; //reset
// load next screen....
}
//if nav_items does not yet exist, try 5 times, then give up!
else {
//set a timer
if(reloadTimer == false){
reloadTimer = setInterval(function(){checkJSON(nav_items)},300);
console.log(item + " not found. Attempts: " + loadAttempts );
}
else {
if(loadAttempts <= 5){
console.log(item + " not found. Attempts: " + loadAttempts );
} else {
clearInterval(reloadTimer);
reloadTimer = false;
console.log("Giving up on " + item + "!!");
}
}
}
}
I need to grab the height of the window and the scrolling offset in jQuery, but I haven't had any luck finding this in the jQuery docs or Google. I'm 90% certain there's a way to access height and scrollTop for an element (presumably including the window), but I just can't find the specific reference.
Any help is appreciated! Thanks!
So, given a key, I want to find the next property in an object. Then, I want to return the value of the NEXT property. I can not rely on the keys to be ordered or sequential (they're uuids). Please see below for trivial example of what I want:
var db ={
a: 1,
b: 2,
c: 3
}
var next = function(db, key) {
// ???
}
next(db, 'a'); // I want 2
next(db, 'b'); // I want 3
I also want a prev() function, but I'm sure it will be the same solution.
This seems like such a trivial problem but I can't for the life of me figure out how to do it.
Happy for the solution to use underscore.js or be written in coffeescript :)
var obj = {},ar = [],nothing=null,empty=undefined,word ='string',headorTail = true;
console.log(typeof obj) //object
console.log(typeof ar)//object
console.log(typeof nothing)//object
console.log(typeof empty)//undefined
console.log(typeof word)//string
console.log(typeof headorTail)//boolean
But how can i get the type of obj,ar,nothing as "object, array,null" - what is the best way to achieve this?
I want to preload images but ensure they are loaded before continuing. How can I do this?
The following does not work as it sends off the load request only, but doesn't wait till the image is loaded. So it is possible that the image isn't loaded when requested soon after.
jQuery.preloadImages = function () {
for (var i = 0; i < arguments.length; i++) {
jQuery("<img>").attr("src", arguments[i]);
}
}
$.preloadImages("img1.jpg","img2.jpg");
I have an array of strings that are valid jQuery selectors (i.e. IDs of elements on the page):
["#p1", "#p2", "#p3", "#p4", "#p5"]
I want to select elements with those IDs into a jQuery array. This is probably elementary, but I can't find anything online. I could have a for-loop which creates a string "#p1,#p2,#p3,#p4,#p5" which could then be passed to jQuery as a single selector, but isn't there another way? Isn't there a way to pass an array of strings as a selector?
EDIT: Actually, there is an answer out there already.
http://lalalafactory.blogspot.com/2008/02/light-alet-lightalertjs.html
Can anyone tell me what to change that JS confirm button will also work. I add
function confirm(obj){
new LightAlert(obj);
}
but still works like alert not confirm.
Hi,
I'm trying to make wysiwyg editor with content editable divs and I'm inserting html with document.execCommand('insertHTML', false, html); but the problem is, when i insert link, and then i want to write after it continues to write INSIDE that link.
EXAMPLE:
how it does now:
Hello, stackoverflow.com MyTextAfterLink
how it should be:
Hello, stackoverflow.com MyTextAfterLink
How could i fix this? Thanks.
Hi All,
I have to solve a defect.
The defect is there is a scroll bar attached to the vertical cascading menu. When I try to scroll through the items using the scrollbar , the menu disappears. That is, When i place the mouse over the scrollbar the menu disappears. But when i scroll the items through the mouse, the scrollbar is also moving.
Can anyone help me out in this issue?
Please forward ur ans to *[email protected]*
Thanks,
Manochitra.
I'm creating jQuery plugins using the pattern from the Plugins Authoring page:
(function($) {
$.fn.myPlugin = function(settings) {
var config = {'foo': 'bar'};
if (settings) $.extend(config, settings);
this.each(function() {
// element-specific code here
});
return this;
};
})(jQuery);
My code calls for several private methods that manipulate this. I am calling these private methods using the apply(this, arguments) pattern. Is there a way of designing my plugin such that I don't have to call apply to pass this from method to method?
My modified plugin code looks roughly like this:
(function($) {
$.fn.myPlugin = function(settings) {
var config = {'foo': 'bar'};
if (settings) $.extend(config, settings);
this.each(function() {
method1.apply(this);
});
return this;
};
function method1() {
// do stuff with $(this)
method2.apply(this);
}
function method2() {
// do stuff with $(this), etc...
}
})(jQuery);
For some reason DOMParser is adding some additional #text elements for each newline \n for this url
http://rt.com/Root.rss
...as well as many other RSS I've tried. I checked cnn/bbc feeds, they don't have newlines and dom parser handling them nicely. So I have to add the following before parsing it
var xmlText = htmlText.replace(/\n[ ]*/g, "");
var xmlDoc = parser.parseFromString(xmlText, "text/xml");
Server is returning text/xml.
var channel = xmlDoc.documentElement.childNodes[0];
this returning \n without my code above and channel with correction.
I have a form that I use JQuery, I don't think I need to put code in this post, the question is pretty basic.
But I would like to block the form from submitting when people press the Enter Key or the Return Key.
At the same time, I have textareas, where the user will need to be able to press the Enter / Return keys.
I'm working with Youtube API and Jquery. With a certain script I can get Youtube Feeds as an image, take a look at the example: JsFiddle
I'm trying to do a Jquery click event which will have to invoke another script called 'embedly' like this:
$("a").click(function(event) {
event.preventDefault();
$(this).embedly({
chars: 220,
nostyle: true,
key:':41f042ec20b04dda84448dc4a46d357d'
});
});
It doesn't seem to work. When I do this from my desktop the click does not invoke the embedly part and also goes to the url regardless of the prevent default.
Hi Folks,
I've scanned trough the documentation but I can't find out how I to get the field to get the datepickers value AND let it be editable using my keyboard numpad. So filling/editing the date without using the datepicker.
I hope my question is clear cause I don't know how the formulate it otherwise..
Greetings
Adding a validator to my form:
jQuery.validator.addMethod('whatever', function(val, el) {
// whatever goes here
}, 'A maximum of ' + $('#my_id_here').val() + ' categories can be selected.');
This doesn't fly. I always get undefined. Is this a good, simple way to do this?
Thanks
Hello
i just wander where can i find a tool that takes in my case java script string that is
unescape and converting it to escaped string so i could use it as string value in c++
for example characters like " i need to convert it to \"
i need something smart and not just replace all function .
Hi,
I've been experimenting with this plugin http://valums.com/edit-in-place/, so far so good... But i ran into this problem. I want to update my page when update or new request to save data is sent but if i update this function(edit-in-place) it will add second set of buttons, third, fourth and so on. How could i tell it that it would update just on that returned data, but not all elements? I have an idea it has to do something with each function of jquerys, but I'm not sure as I'm quite new to jquery. Thanks for any help!
I have attribute value as:
<div id = "zone-3a-2f-2f-2fPortal-2fPages-2fHome-2fZones-2fLeft-2f-7ccomponent-3a-2f-2f-2fSpm-2fComponents-2fPromotion-2f" class = "promotion">
Now I want to get only portion of it, say Promotion and its value 2f, how can I get this using jquery ? Do we have built in function for it ?
$.ajax(
{
url : "http://search.twitter.com/search.json?q=google&lang=en&rpp=10&since_id=&callback=?",
dataType : 'json',
success : function(data)
{
alert(data.results.length);
}
});
How exactly is this working ? I mean the cross-domain request.
For example, i associate following function with some element
$('table#users tbody tr:first #save').click(function(){
$(this).closest('tr').remove();
});
Now, if i don't know where this function is stored, is there a way to view associated with click() code? In above example, i want a way to view that in firebug, or in another way
$(this).closest('tr').remove();
If I'm writing in console following, i'm get a link to dom inspector
>>> ($('table#users tbody tr:first #save').click)
function()
but link is for jquery library, not the code i want.