I discover a strange bug in Konqueror 3.1.1.
I design a javascript application which acts in one file called
example.html. At the beggining of this js i write:
if (document.images)
{
folderopen= new Image(16,16);
folderopen.src="http://www.sergioamo.8m.com/buttons/folder_open.png";
folderclose= new Image(16,16);
folderclose.src="http://www.sergioamo.8m.com/buttons/folder_close.png";
}
functions....
....
...
..
and my javascript works perfect.
If i write:
if (document.images)
{
folderopen= new Image(16,16);
folderopen.src="./buttons/folder_open.png";
folderclose= new Image(16,16);
folderclose.src="./buttons/folder_close.png";
}
functions...
....
...
..
my javascript does not work properly. Does anyone knows if is imposible
to use relative references with konqueror 3.1.1 or which is the problem?
I am creating a chat script that uses PHP and Javascript. For part of it I need to empty one of the text boxes. The scripts I use work fine in IE and Firefox, however the the text box will not clear in Opera and Konqueror. I have tried the follwoing: document.getElementById('commentbox').innerHTML = '' and document.chatform.comment.value = "";
Like I said they are both fine in IE and Firefox, but not in Konqueror or Opera. I have searched for hours looking for code that will work.
Is there an equivalent in Konqueror's KJS engine to Gecko's __defineGetter__() and __defineSetter__() methods? Our web application uses a ton of Javascript, written based on Internet Explorer's object model as that's the primary platform that we're supporting. For Netscape support we uses __defineGetter__() and __defineSetter__() to emulate the many IE-only properties. I've tested our site using Safari, and to my surprise, it renders perfectly. Alas, it's completely non-functional. If it's somehow possible, I'd love to write a similar emulation library for KJS so that our non-Windows users would have an alternative to crummy Netscape/Mozilla.
I am trying to capture the image coordinates when a user clicks on an image. My code is working in Firefox, Mozilla, Netscape, IE, and Opera, but fails under Konqueror (and I suspect Safari). The code below fails in Konqueror when the page is scrolled down; the coordinates are off by the scroll amount.
My code in the html img tag: onClick="MLDot(event)"
The left frame has a DHTML-generated tree of links (to images). The right frame displays the image link you click in the tree of links.
It works great on all browsers except Konqueror/Safari, where it displays the first image link you click on in the tree of links. But then subsequent clicks on other links do nothing.
That is, the first time you click on a DHTML-generated link, Konqueror/Safari loads the corresponding image in the other frame. However, after that, when you click on links, the other frame is not updated.
Is it true that Javascript has no clone() method, to pass an object by copy of value instead of reference?
If I have an object and want to make an array out of all of its instance variables, I can loop through it and pass its values to a new array, and the class instances will be passed by copy and not by reference?
Example 9.3: References Themselves Are Passed by Value
// This is another version of the add_to_totals() function. It doesn't // work, through, because instead of changing the array itself, it tries to // change the reference to the array. function add_to_totals2(totals, x) { newtotals = new Array(3); newtotals[0] = totals[0] + x; newtotals[1] = totals[1] + x; newtotals[2] = totals[2] + x; totals = newtotals; // this line has no effect outside of the function. }
Note that this rule applies not only to pass-by-reference, but also copy-by-reference. You can modify an object through a copy of a reference, but changing the copied reference itself does not affect the object nor the original reference to the object. This is a more intuitive and less confusing case, so we don't illustrate it with an example.
I'm currently engaged on a dissertation which is investigating AJAX technologies and I was wondering if anyone had any references that might shed light on the subject?
I will of course carry out a literature review but in the mean-time has anyone any (preferably print based) sources of data on AJAX?
I am a bit new to JavaScript objects, I have the following object:
LinkTest=function() { // init }
LinkTest.prototype.eventHandler=function(){ // the call below fails, as 'this' refers to the link that // generated the event, and not the instance of LinkTest object this.doSomething(); }
LinkTest.prototype.doSomething=function() { // do something! }
So basically when you register a link, the onclick event handler gets a reference to LinkTest's eventHandler function. Now when the user clicks on the link, the 'this' refers to the link... how do I reference the instance of LinkTest object from within the eventHandler function?
Apparently, there is a page with multiple frames, where one of the frames is a "hidden" frame, and is there just to contain one or more "fields" that are referenced from other frames.
Supposedly, if a user "sits" somewhere in this set of pages for several minutes and then tries to do something, the page redisplays, but an inter-frame reference (to the "hidden" frame) fails with some sort of a "No permission" error. If the user navigates through the site with no real delay, they don't see this problem. This is the situation I need to understand.
I'm assuming that the "No permission" error occurs when a frame that was obtained from domain "foo" tries to reference a frame that was obtained from domain "bar" (I'm not sure of the correct terms in the context of JavaScript). Under normal operation, all of the frame contents are obtained from the same domain (I believe).
My theory is (without much information yet) that there must be a proxy/cache server in between. When the user navigates through the site with no delays, all of the frames are obtained from the same server (either the cache server or the target server, I don't know which). However, when the user "sits" for a while, I'm guessing that the cache server hits a content timeout, and a redisplay of the page causes one frame to be obtained from the target server, and one from the cache server.
Does this seem like a reasonable explanation for what we might be seeing? What are useful strategies for fixing a problem like this?
I am trying to make a function that checks/unchecks a checkbox when a specific <td> is clicked. I need to use this same function for several checkboxes in the page so I want to just pass it the name of the checkbox I want to affect as a variable and use it in the object reference lines. BUT, this doesn't work. I can pass the variable to the function as I've used alert(variable) to test this. But it doesn't work when I put it in a line like this "document.forms[0].variable.checked=true;". Code:
THE QUESTION: How do I get a reference to my Object when processing an event handler bound to an html element ?
CONTEXT: Sorry if it is a bit long.
I am developing a JS calendar tool. One of the requirements is that the calendar will need to display a varying number of months (1..3) depending on the calling page. Imagine 1, 2 or 3 calendar pages side by side as required.
I have built a grid object that will contain one month's dates with the day names at the top. The calendar object inherits the grid object as an array of "calendar pages" - one grid per month and the calendar provides the content for each grid. I will use the grid object for another completely different object later and so I want to use good OOP encapsulation. The grid is a table generated on the fly and is "dumb" as far as what it is used for.
I have attached an onlick event to each cell of the grid. Using OOP priciples I want the calling program (the calendar object in this case) to provide a function to handle the click and the grid object will provide to the calendar the row and column of that cell as well as the grid number (so the calendar can work out which date was clicked since it knows what the data means and the grid doesnt). Code:
I'm working on a project that I want the user to be able to change the color theme of the site. For some reason if I go over about 20 themes or css references it breaks the site. Any idea why this is? if so, how can I get it to accept say 50 themes?
1) is getRule a local variable or global variable, as it has no var keyword, yet it is an inner function of Validation? So without var, I think global, but being an inner function, I think local. So I'm not sure which.
2) In this line of code: var rule = $.Validation.getRule(types[type]), getRule returns rules, which is just a local variable in Validation. I always see that you return functions, but how does returning a local variable that's just an object literal and not a function be able to return true or false? Now the value of rules is an object literal, and this object returns true or false. So we are basically allowed to use return keyword with local variables that are object literals and not functions?
3) In this line, is foo(age) being called, or is it just being assigned to bar OR is it being called and THEN assigned to bar: var bar = foo(age);
4) Now for the most confusing: age is obviously an object reference as opposed to a literal in the example. Does that make a difference in regards to closures? Note that I read a number of books, including JavaScript Programmer Reference and Object Oriented JavaScript and jQuery cookbook, which compare primitives vs reference types and how primitive types store directly in memory whereas reference tpyes reference memory, so if one reference changes, they all change where primitive remains ingrained. But when assigning a function as a reference like this, how does that affect the object "age" when passed into bar?
Code: function foo(x) { var tmp = 3; return function (y) { alert(x + y + tmp); x.memb = x.memb ? x.memb + 1 : 1; alert(x.memb); }} var age = new Number(2); var bar = foo(age); // bar is now a closure referencing age. bar(10);
I'm not sure why, but the Console.focus() and Console.writeln() methods just don't seem to be able to use the DOM references stored in Console.STDIN and Console.STDOUT. Everything's fine in the constructor, but other methods can't seem to use them.
My site's working perfectly in the other browsers, and when I delete line 28 (see below) it works in IE but not exactly how I want. Is there a way to retain two jquery references on a single page in IE?
Is it possible to test whether two objects are equal using the data they contain inside and not comparing their pointers with ==?
Well actually of course there is but...
Is there a way to do it without actually looping through the object, instead maybe something that came with JS? (something like a .equals() method from other programming languages.)
I am confused about the true difference between the two below examples.
first example:
// Demonstrating a problem with closures and loops var myArray = [āAppleā, āCarā, āTreeā, āCastleā]; var closureArray = new Array();
[code]....
Here we iterate through the length of myArray, assigning the current index of myArray to theItem variable. We declare closureArray 4 times as an anonymous function. The anonymous function in turn declares the predefined write() function, which is passed parameters. Since write() is in closureArray() a closure is created??? During each iteration, theItem is reassigned its value. The four closures reference this value. Since they reference this same value and since this value is reassigned ultimately to the value of the fourth index position, tHe time we execute closureArray later on, all four closures output the same string. This is because all four closures are within the same scope "the same environment" and therefore are referencing the same local variable, which has changed.
I have a couple of problems with this example:
1) I thought a closure is a function that is returned - the inner function is not returned above.
2) theItem is not even a local variable of the parent function (closureArray) - I thought in order for a closure to work, the inner function only accesses the local variables of the outer function, but in this case the local variable is defined OUTSIDE of the parent function.
3) the "the four closures are sharing the same environment." The thing is even in the second example, they are sharing the same environment.
Second example:
// A correct use of closures within loops var myArray = [āAppleā, āCarā, āTreeā, āCastleā]; var closureArray = new Array();
[code]....
Here we iterate over the length of myArray (4 times), assigning the index of myArray to theItem variable. We also return a function reference to the closureArray during each iteration (closureArray[i]), where i is index number so we assign 4 functon references. So when we iterate through myArray, we immediatelly call the writeItem() fucntion passing an argument of theItem at its current value. This returns a child anonymous function and when that child function is called, it will execute a block that calls the predefined write() method. We assign that returned anonymous function to the variable closureArray. Hence, closureArray holds a reference to that anonymous function. So closureArray during each iteration holds a reference to the anonymous function and we later call closureArray, which in turn calls the anonymous function, therefore calling the predefined write() function to output the local variable of the parent function. This outputs each distinct index of myArray.
This is because since we created the closure, when we call writeItem, passing theItem argument, since theItem is a local variable of the parent function of the closure, it is never destroyed when we later call closureArray (the reference to the child anonymous function)? Yet weren't we using a closure in the first example as well? So whey wasn't those variables preserved?
I don't think it has anything to do with assigning a returned anonymous function to closureArray. Even though an anonymous function creates a new memory position in the javascript engine, therefore not overwriting the other function references we create during the iteration, it's still referring to a local variable declared outside the reference. So if it's about the closure retaining value of parent's local variable even after exiting the parent function allowing for the current indexes to be preserved, then why did the closure in the first example fail to retain each index?
This works fine in IE: the div is positioned relative to the td of menu1. However, in Mozilla it doesn't work. The div becomes relative to the top of the page.
I would like to display any item that has ID associated with it on the top-left corner of its physical location (20px up and 20px right) with yellow background and red foreground.
If you follow the evolution of software development on Internet, you may have the impression that every new development is Web based and that the main areas of concern are whether you should develop new application with Ruby on Rail or if you should choose Flash rather than Ajax for the interface. However, if you ask developers, you may find that the Web is not as ubiquitous in their work as you may think.
Even if 66% of the participants develop the majority of their new applications with a browser as the interface, there is still a large portion of developers that are working today for operating contexts that are outside the Web world, like embedded software or Windows applications. Code:
I'm having an issue using .get and a callback. Basically, unlessI use a fully quantified path when I deploy my site the call doesn't work. When I'm developing on localhost, the site works fine. It's an ASP.NET MVC site. I'm fairly new to jQuery. If I replace the code with an absolute path, all seems fine. Obviously I'd rather use relative paths. I'd be grateful for any insight you could offer.
1. I have some links that open with Javascript. The HTTP links work just fine, but I have one link that is supposed to open a picture in a new window. The picture is stored in the root/images folder. So it's supposed to be a relative path, but no matter what I do, I get an error page. (images/snailmail.jpg)
2. I have added a mouserollover funtion to change a small picture on the page. I am trying to add a second function to that function, to stop the scrollbar in the lower left corner as long as the mouse hovers over the picture. For the first picture, it works fine, but with the 2nd picture which allready has a mouseover function, I am not sure what to do.
I've wondering if anyone knows of a script where I can scroll a div down the page as the user scrolls down the page. You know, like those annoying ads do sometimes
I've googled for some, but the ones I've tried only work to varying degrees when I want the div positioned relatively. The reason I want it relatively positioned is that my site is centred, and fixed-width.
Basically, I need it to scroll up and down in a 'side bar' area, and the main problem I seem to be having: not scroll below my footer area.
The two pages for preloading below seemed to preload images IF I used an absolute path but they don't preload the images if I just used relative paths like the ones below.
Give it a try. The two pages below using relative paths won't work. Then try changing the paths of the images in both pages to use absolute path(with http://) which will work.
But I want to use relative paths. What can be done? Other than inserting 1x1 size of the images I want to preload. Code: