'in' Operator And Feature Detection Technique...
Feb 9, 2006
We all know that feature detection technique works from very beggining
of user-agents supporting JavaScript. We can alway check if eg.
document has a write property or smth else:
if(document.write) {
}
We could do that for all of objects, so i have been surprised when i
found 'in' operator, which for above example would be used like this:
if("write" in document) {
}
So i have questioned myself what for ? I can always do:
if(document["write"]) {
}
or even
var prop = [...];
if(document[prop]) {
}
which is supported better then 'in' operator ('in' is supported since
W. IE 5.5 and NN 6 - around 2000 year). I can only guess that 'in' was
provided in W. IE 5.5 only for convenience... but that is my guess and
someone more knowlegable could write here some more opinions on this
operator...
View 22 Replies
ADVERTISEMENT
Sep 1, 2006
I'm picking apart the Yahoo! UI event.js library and stripping it down
to just what I need. I'm also trying to make the parts I use better.
I'm stumped on how to fix the code for the getPageX() method. This
method is supposed to give the same value in IE as other browsers for
the event position relative to the left of the page. This value will be
greater than the position relative to the left of the browser if the
browser is scrolled to the right. What would be the appropriate feature
detection to use for the conditional in the following line?
if ( this.isIE ) {
Thank you,
Peter
isSafari: (/Safari|Konqueror|KHTML/gi).test(navigator.userAgent),
isIE: (!this.isSafari && !navigator.userAgent.match(/opera/gi) &&
navigator.userAgent.match(/msie/gi)),
getPageX: function(ev) {
var x = ev.pageX;
if (!x && 0 !== x) {
x = ev.clientX || 0;
if ( this.isIE ) {
x += this._getScroll()[1];
}
}
return x;
},
_getScroll: function() {
var dd = document.documentElement, db = document.body;
if (dd && dd.scrollTop) {
return [dd.scrollTop, dd.scrollLeft];
} else if (db) {
return [db.scrollTop, db.scrollLeft];
}
return [0, 0];
}
View 10 Replies
View Related
May 5, 2003
I'm going to make an attempt at coding a nice tree menu that is decent with browser support.
I want the tree to be displayed on all browsers (well, within a decent range). Of course, on older browsers, the menu won't be as functional.
Now, I'm going to be combining the javascript with a server-side language (asp.NET) and I'll be able to do some basic browser detection on the server.
But, I read about javascript object detection and am wondering how well that works exactly.
Like, what if a browser that doesn't support objects period tries to run some object detection code? Also, which browsers support user defined objects?
See, I'm thinking of breaking down the script in 3 categories. Browsers that won't get any javascript... these would be the browsers that don't support object detection, browsers with basic javascript... with these I would be able to code my own object and I would test for different features. And then there would be the browsers that can run it all.
So, basically, my question is what browsers support what features and how should I break down my code between them? A long time ago (back in the Netscape 4 / IE4 days) I did some javascripting, but since then I haven't really done any. I remember that NS4 didn't support div tags but supported layers... anyway, it got really messy.
View 4 Replies
View Related
Sep 27, 2011
I'm planning on making a website which is mainly just a gallery of images.
The site will essentially look like one page with a jCarousel on it, when the user clicks left or right on the carousel, I would like the URL to change but for the animation not to get interupted.
I would also need to change some HTML on the page too, essentially each image will have a Facebook 'like' button and that will need to change to the corresponding URL.
The carousel is going to be database driven and dynamically built up with potentially 1000's of images, so I'm not sure what the best technique for this would be? I'm building it in ASP.NET / Ajax and using the SlideJS carousel [code]...
View 1 Replies
View Related
Oct 9, 2009
I'm looking for different JS form validation techniques. I've seen quite a few but nothing that really stands out. I'm particularly interested in finding design techniques...ie: how and where are the errors displayed inside a form? I realize that I can't count on JS for validation, but I'm trying to add an assistive technology to make a web form feel more like a web application. I'd love to see your favorite way of displaying form errors via JS. I've got a few of my own but if you've ever tried to do this you know it's a difficult problem to handle the general case.
View 7 Replies
View Related
May 29, 2011
This is what I'm attempting at the moment, links is an array. Should this work? I understand that HTML headers cannot contain complex datasets like arrays, so what format is the data sent in? Ie. how do I decompose the array on the PHP end? Or is there a better way entirely of doing this?
$.ajax({
type: "POST",
url: "http://asdfasdf.heliohost.org/multiurl.php",
[code]....
View 1 Replies
View Related
Aug 6, 2007
Just wonder whether jaavscript can perform the NOT IN / IN as below:
if form.mytext.value NOT IN ("MYTEXT") {
alert("Mytext");
}
I did try, but not alert is displayed ad not error shown as well.
View 5 Replies
View Related
Jul 23, 2005
I don't actually have a mac with which to test this, but I'm informed
by a colleague that one of my scripts has failed in IE on the Mac;
endless twiddling seems to point to the ternary operator as culprit.
I asked him to check that javascript:alert(true?"Yes":"No"); gave an
alert when pasted into the address bar and he's reported that it does
not.
javascript:alert("someString"); works quite happily.
Can anyone confirm this bug or help narrow it to a single version? It
seems a fairly large bug to have gone so under-reported, gooooogling
for "mac ie ternary operator" doesn't return anything helpful.
View 4 Replies
View Related
Aug 13, 2005
Is there any way to call the new operator as a method (function)? The
reason is that I've got IE as a COM object (Imagine I've brought up IE
using VB) and it's easy to call every method of any DOM element
(including window). But if I want to create a new object, then it's
more complicated. Of course I could always execute js code (using
window.execScript) which will create the object and save it as a
variable on the window object and then pick it up from the COM creator,
but really...
Consider the following page snippet which nicely adds an option to the
empty select element. Of course, I could use the W3C createElement,
addChild, muckWithDOM approach to avoid the execScript, but both of
these are going to add huge amounts of time and substantial complexity
to an otherwise one liner:
<form method=pos action=''>
<select name=sel id=sel></select>
<script type='text/javascript'>
var sel=document.getElementById('sel');
sel.options[0] = new window.Option("foo", "bar");
</script>
</form>
Can't I do something like
window.Option.newInstance("foo", "bar")
in place of the
new window.Option("foo", "bar") ?
View 5 Replies
View Related
Jul 30, 2002
I have a for loop and would like to increment a variable for (let's say) 2 instead of one (++). How can I do that?
I have tried for instance x + 2 instead of x++ but when I try it in IE an error saying that a script is making IE to run slowly and then nothing happens. So how to do this?
View 19 Replies
View Related
Dec 14, 2006
<script>
var sd=function(){
return{
f1:function(){
alert('f1');
},
f2:function(){
alert('f2');
}
}
}();
sd.f2();
</script>
when execute sd.f2();it will alert f1,who can tell me why?
View 5 Replies
View Related
Mar 10, 2010
How you might achieve the following without using eval()? I've come up a bit short:
function addOrSubtract(operator) {
var a = 10;
var b = 5;
var answer = eval(a + operator + b);
alert(answer);
}
addOrSubtract('+') // alerts 15
addOrSubtract('-') // alerts 5
View 3 Replies
View Related
May 20, 2009
I'd like to know which is faster or have a better performance between :
Code JavaScript:
if (flag) {
var v = "something";
} else {
var v = "else";
[Code]...
View 8 Replies
View Related
Nov 13, 2010
this.delete = function(obj){
..
Is that it ? I can't have delete ? Or can this be written in some other way, including delete ?
View 4 Replies
View Related
Sep 23, 2011
I want to combine two click events to one function.Is there a syntax way like when you click this or you click that do something [code]
View 1 Replies
View Related
Feb 25, 2009
I am trying to run some code that will check if the user enters two values from 'depart' and 'arrival' select lists that would make up an invalid journey:
var cdate, ctime, cdepart, carrive, cname;
with(window.document.example) {
cdate = date;
ctime = time;
cdepart = depart;
carrive = arrive;
cname = name;
}
if(trim(cdepart.value) == 'Uptown' && trim(carrive.value) == 'Downtown'){
alert('invalid journey');
cdepart.focus();
return false;
}function trim(str){
return str.replace(/^s+|s+$/g,'');
}
However when I select the values the alert is not shown? I think My syntax is okay, maybe not?
View 5 Replies
View Related
Aug 22, 2010
It's well know that the ternary operator syntax is something like so:
Code:
(test) ? true doThis : false doThat
Suppose that in case condition is false we want do nothing. How to code "do nothing"? May I let it blank or there are an appropriate syntax?
View 10 Replies
View Related
Jul 14, 2010
What kind of logical error am I making? I want the alert(); to execute if both of the variables (cjob and czip) are blank, but the only way I can get it to work is if I replace && with ||.
if(trim(cjob.value) && trim(czip.value) == '')
{
alert('Hello');
}
View 2 Replies
View Related
Dec 7, 2009
If number is more than 24 digits, modulus operator is not giving correct output [code]...
View 4 Replies
View Related
Aug 13, 2010
anotherVar should be -1 if there are no matches, but it doesn't seem to work var string = "abadafa"; var matches = string.match(/a/gi); //doesn't work with /z/ for example
var anotherVar = matches.length || -1; The default operator should return the second value if the first is null or false, and according to try { alert(matches.length);
}
catch (e){
alert(e); //alerts null
} it's null.
fyi: http://helephant.com/2008/12/javascript-null-or-default-operator/
View 22 Replies
View Related
Dec 22, 2009
I am doing a script, like:
I have anonymous function "xhr.onreadystatechange = function() {}" in the method "this.update" of an object that receives 2 arrays through AJAX. I need these 2 arrays to be assigned to this.images and this.folders, respectively, through this anonymous function. I try to use "var self" technique, but it doesn't work.
View 11 Replies
View Related
Feb 3, 2011
I have a set of regular expressions that make heavy use of the | operator on sections that I do not really need to extract a match from. For example:
Code:
var regexp = /([A-Z][A-Za-z]+) (jumps( high)?|leaps|bounds) over ([A-Z][A-Za-z]+) and (grabs|snags|gets) (a|an|the) (apple|orange|pear|grapes)/
The important part for extracting from the match array after using regexp.exec() are the names (the ([A-Z][A-Za-z]+) parts), I don't care which of the other things are matched. The problem is that using the | operator seems to necessitate using the () and adding a term to the match. This makes it difficult to know which term in the array will be the names, especially after editing the middle.So I'd like to be able to use the | operator on words and phrases without adding terms to the match array.
View 2 Replies
View Related
May 6, 2010
trying to find a good rotating box with SEO content.[URL]
View 5 Replies
View Related
Feb 17, 2007
I was playing around with the compose feature of gmail today and I noticed that it seemed to have an extremely intelligent auto-save feature. What intrigued me about it was that it only seemed to auto-save the document when you were not working on it and when there was actually something that needed to be done.
However the most interesting (i.e., bit that stumped me) was how while in the middle of auto-uploading a large attached file I am able to edit the e-mail and yet when it has finished uploading the attachment (and the page seemingly refreshes) the changes I made to the e-mail are still there.
Could anyone be so kind as to enlighten me as to just how exactly the auto-save feature works (as I am interested implementing something similar for my own site), especially in the region of attachment handling.
I know that they must have some kind of JavaScript on-key-press callback that detects when you are working on a document but that is about all I can extrapolate.
View 1 Replies
View Related
Jul 9, 2007
i am trying to get to work and i don't get why its not working so i am going to post it here and if someone who is smarter then me could come on and let me know why its not working and how i can fix it. if you have any questions let me know and i would be glad to answer them. Code:
View 10 Replies
View Related
Oct 2, 2006
I have a property site and would like users to be able to click a button or tick a box to enable them to save a listing & then when they have finished searching they can then click on a 'view saved properties' button and each listing, or a link to each listing will be displayed on a seperate page so they can then go back to all their saved listings.
View 2 Replies
View Related