Search Results

Search found 23708 results on 949 pages for 'javascript'.

Page 10/949 | < Previous Page | 6 7 8 9 10 11 12 13 14 15 16 17  | Next Page >

  • javascript addEventListener onStateChange not working in IE

    - by user347456
    Hi, I have two colorbox popup boxes which show a youtube video in each. When they're finished playing, I'm trying to have them automatically close the colorbox window. This code below works perfect in firefox, but in IE I can't get addEventListener to work. I've tried attachEvent with no success. Can anybody offer any suggestions as to how to solve this? It seems simple but I'm exhausted trying to find a solution. By the way, this is my first time as stackoverflow and it's very impressive. var params = { allowScriptAccess: "always" }; var atts = { id: "ytplayer1" }; swfobject.embedSWF("http://www.youtube.com/v/VIDEO1&rel=0&hl=en_US&fs=0&autoplay=1&enablejsapi=1&playerapiid=ytvideo1", "popupVideoContainer1", "640", "385", "8", null, null, params, atts); var params2 = { allowScriptAccess: "always" }; var atts2 = { id: "ytplayer2" }; swfobject.embedSWF("http://www.youtube.com/v/VIDEO2&rel=0&hl=en_US&fs=0&autoplay=1&enablejsapi=1&playerapiid=ytvideo2", "popupVideoContainer2", "640", "385", "8", null, null, params2, atts2); function onYouTubePlayerReady(playerId) { if(playerId == 'ytvideo1'){ var ytplayer = document.getElementById('ytplayer1'); ytplayer.addEventListener("onStateChange", "onytplayerStateChange", false); } else if(playerId == 'ytvideo2'){ var ytplayer = document.getElementById("ytplayer2"); //ytplayer.addEventListener("onStateChange", "onytplayerStateChange", false); if (ytplayer.addEventListener) { ytplayer.addEventListener("onStateChange", "onytplayerStateChange", false); } else if (ytplayer.attachEvent) { ytplayer.attachEvent("onStateChange", onytplayerStateChange); } } } function onytplayerStateChange(newState) { if(newState == 0){ $.fn.colorbox.close(); } }

    Read the article

  • Simple javascript to mimic jQuery behaviour of using this in events handlers

    - by Marco Demaio
    This is not a question about jQuery, but about how jQuery implements such a behaviour. In jQuery you can do this: $('#some_link_id').click(function() { alert(this.tagName); //displays 'A' }) could someone explain in general terms (no need you to write code) how do they obtain to pass the event's caller html elments (a link in this specific example) into the this keyword? I obviously tried to look 1st in jQuery code, but I could not understand one line. Thanks!

    Read the article

  • JavaScript: Keeping track of eventListeners on DOM elements

    - by bobthabuilda
    What is the best way to keep track of eventListener functions on DOM elements? Should I add a property to the element which references the function like this: var elem = document.getElementsByTagName( 'p' )[0]; function clickFn(){}; elem.listeners = { click: [clickFn, function(){}] }; elem.addEventListener( 'click', function(e){ clickFn(e); }, false ); Or should I store it in my own variable in my code like below: var elem = document.getElementsByTagName( 'p' )[0]; function clickFn(){}; // Using window for the sake of brevity, otherwise I wouldn't =D // DOM elements and their listeners are referenced here in a paired array window.listeners = [elem, { click: [clickFn, function(){}] }]; elem.addEventListener( 'click', function(e){ clickFn(e); }, false ); Obviously the second method would be less obtrusive, but it seems it could get intensive iterating through all those possibilities. Which is the best way and why? Is there a better way?

    Read the article

  • Javascript childNodes does not find all children of a div when appendchild has been used

    - by yesterdayze
    Alright, I am hoping someone can help me out. I apologize up front that this one may be confusing. I have included an example to try to help ease the confusion as this is better seen then heard. I have created a webpage that contains a group or set of groups. Each group has a subgroup. In a nutshell what is happening is this page will allow me to combine multiple groups containing subgroups into a new group. The page will give the chance to rename the old subgroups before they are combined into new groups in order to avoid confusion. When a group is renamed it will check to make sure there is not already a group with that name. If there is it will copy itself out of it's own group and into that group and then delete the original. If the group does not already exist it will create that group, copy itself in and then delete the original. Subgroups can also be renamed at which point they will move into the group with the same name if it exists, or create a new one if it doesn't. The page has a main div. The main div contains 'new sub group' divs. Inside each of those is another div containing the 'old sub group' divs. I use a loop through the child nodes of the 'new sub group' div when renaming a group in order to find each child node. These are then copied into a new div within the main div. The crux of the problem is this. If I loop through a DIV and copy all of the DIVs in it into a new or existing DIV all is well. When I then try to take that DIV and copy all of it's DIVs into another or new DIV it always skips one of the moved DIVs. For simplicity I have copied the entire working code below. To recreate the issue click the spot where the image should appear next to the name ewrewrwe and rename it to something else. All is well. Now click that new group the same way and name it something else. You will see it skip one each time. I have linked the page here: http://vtbikenight.com/test.html The link is clean, it is my personal website I use for a local motorycle group I am part of. Thanks for the help everyone!!! Please let me know if I can clarify on anything. I know the code is not the best right now, it is just demo code and my intent is to get the concept working then streamline it all.

    Read the article

  • JavaScript: Doing some stuff right before the user exits the page

    - by Mike
    I have seen some questions here regarding what I want to achieve and have based what I have so far on those answer. But there is a slight misbehavior that is still irritating me. What I have is sort of a recovery feature. Whenever you are typing text, the client sends a sync request to the server every 45 seconds. It does 2 things. First, it extends the lease the client has on the record (only one person may edit at one time) for another 60 seconds. Second, it sends the text typed so far to the server in case the server crashes, internet connection fails, etc. In that case, the next time the user enters our application, the user is notified that something has gone wrong and that some text was recovered. Think of Microsoft or OpenOffice recovery whenever they crash! Of course, if the user leaves the page willingly, the user does not need to be notified and as a result, the recovery is deleted. I do that final request via a beforeunload event. Everything went fine until I was asked to make a final adjustment... The same behavior you have here at stack overflow when you exit the editor... a confirm dialogue. This works so far, BUT, the confirm dialogue is shown twice. Here is the code. The event if (local.sync.autosave_textelement) { window.onbeforeunload = exitConfirm; } The function function exitConfirm() { var local = Core; if (confirm('blub?')) { local.sync.autosave_destroy = true; sync(false); return true; } else { return false; } }; Some problem irrelevant clarifications: Core is a global Object that contains a lot of variables that are used everywhere. sync makes an ajax request. The values are based on the values that the Core.sync object contains. The parameter determines if the call should be async (default) or sync.

    Read the article

  • Capture *all* display-characters in JavaScript?

    - by Jean-Charles
    I was given an unusual request recently that I'm having the most difficult time addressing that involves capturing all display-characters when typed into a text box. The set up is as follows: I have a text box that has a maxlength of 10 characters. When the user attempts to type more than 10 characters, I need to notify the user that they're typing beyond the character count limit. The simplest solution would be to specify a maxlength of 11, test the length on every keyup, and truncate back down to 10 characters but this solution seems a bit kludgy. What I'd prefer to do is capture the character before keyup and, depending on whether or not it is a display-character, present the notification to the user and prevent the default action. A white-list would be challenging since we handle a lot of international data. I've played around with every combination of keydown, keypress, and keyup, reading event.keyCode, event.charCode, and event.which, but I can't find a single combination that works across all browsers. The best I could manage is the following that works properly in =IE6, Chrome5, FF3.6, but fails in Opera: NOTE: The following code utilizes jQuery. $(function(){ $('#textbox').keypress(function(e){ var $this = $(this); var key = ('undefined'==typeof e.which?e.keyCode:e.which); if ($this.val().length==($this.attr('maxlength')||10)) { switch(key){ case 13: //return case 9: //tab case 27: //escape case 8: //backspace case 0: //other non-alphanumeric break; default: alert('no - '+e.charCode+' - '+e.which+' - '+e.keyCode); return false; }; } }); }); I'll grant that what I'm doing is likely over-engineering the solution but now that I'm invested in it, I'd like to know of a solution. Thanks for your help!

    Read the article

  • Detecting a image 404 in javascript.

    - by xal
    After a user uploads a file we have to do some additional processing with the images such as resizing and upload to S3. This can take up to 10 extra seconds. Obviously we do this in a background. However, we want to show the user the result page immediately and simply show spinners in place until the images arrive in their permanent home on s3. I'm looking for a way to detect that a certain image failed to load correctly (404) in a cross browser way. If that happens, we want to use JS to show a spinner in it's place and reload the image every few seconds until it can be successfully loaded from s3.

    Read the article

  • Image viewport with zoom in Javascript

    - by pakore
    I want to display a huge image inside a viewport in a html page. I would like to be able to drag and drop the image to move it inside the viewport, like in Google Maps. Any library where I can find such component? Thanks in advance

    Read the article

  • Binding event handlers to specific elements, using bubbling (JavaScript/jQuery)

    - by Bungle
    I'm working on a project that approximates the functionality of Firebug's inspector tool. That is, when mousing over elements on the page, I'd like to highlight them (by changing their background color), and when they're clicked, I'd like to execute a function that builds a CSS selector that can be used to identify them. However, I've been running into problems related to event bubbling, and have thoroughly confused myself. Rather than walk you down that path, it might make sense just to explain what I'm trying to do and ask for some help getting started. Here are some specs: I'm only interested in elements that contain a text node (or any descendant elements with text nodes). When the mouse enters such an element, change its background color. When the mouse leaves that element, change its background color back to what it was originally. When an element is clicked, execute a function that builds a CSS selector for that element. I don't want a mouseover on an element's margin area to count as a mouseover for that element, but for the element beneath (I think that's default browser behavior anyway?). I can handle the code that highlights/unhighlights, and builds the CSS selector. What I'm primarily having trouble with is efficiently binding event handlers to the elements that I want to be highlightable/clickable, and avoiding/stopping bubbling so that mousing over a (<p>) element doesn't also execute the handler function on the <body>, for example. I think the right way to do this is to bind event handlers to the document element, then somehow use bubbling to only execute the bound function on the topmost element, but I don't have any idea what that code looks like, and that's really where I could use help. I'm using jQuery, and would like to rely on that as much as possible. Thanks in advance for any guidance!

    Read the article

  • Use Javascript to retrieve HTML on same-domain

    - by ehfeng
    Say I have an xml document on a webserver (www.example.com/example.xml). On my main page, if I would like to retrieve that document as a string, how can I do this? I tried xmlhttprequest - maybe I'm using it wrong? It returns it as "undefined." Help? var xml_page = new XMLHttpRequest(); xml_page.open("GET", "http://www.samedomain.com/example.xml", true); if (xml_page.readyState == 4 && xml_page.status == 200) { var data = xml_page.responseText; } document.write(data);

    Read the article

  • JavaScript: input validation in the keydown event

    - by c411
    Hi, I'm attempting to do info validation against user text input in the process of keydown event. The reason that I am trying to validate in the keydown event is because I do not want to display the characters those that are considered to be illegal in the input box at the beginning. The validation I am writing is like this, function validateUserInput(){ var code = this.event.keyCode; if ((code<48||code>57) // numerical &&code!==46 //delete &&code!==8 //back space &&code!==37 // <- arrow &&code!==39) // -> arrow { this.event.preventDefault(); } } I can keep going like this, however I am seeing drawbacks on this implmentation. Those are, for example, Conditional statement become longer and longer when I put more conditions to be examined. keyCodes can be different by browsers. I have to not only check what is not legal but also have to check what are exceptionals. In above examples, delete,backspace, and arrow keys are exceptionals. But the feature that I don't want to lose is having not to display the input in the textarea unless it passes the validation. (In case the user try to put illegal characters in the textarea, nothing should appear at all) That is why I am not doing validation upon keyup event. So my question is, Are there better ways to validate input in keydown event than checking keyCode by keyCode? Are there other ways to capture the user inputs other than keydown event before browser displays it? And a way to put the validation on it? Thanks for the help in advance.

    Read the article

  • this.select() and javascript events on forms

    - by aloishis89
    I have a form box that I want to be always selected. I was able to get it to select everything in the box when it is clicked (using onFocus="this.select()") but I want it to be selected 100% of the time. The text in the box will be always changing, so I tried using onChange="this.select()" but that didn't work. Here's what I have: <form> <input type="text" id="txt1" size="30" maxlength="1" onkeyup="showHint(this.value)" onFocus="this.select()" onBlur="this.select()" onChange="this.select()" value="Click here, then press a key"/> </form> Basically I just tried to call everything in hopes that something would work, but it is still acting as if only onFocus="this.select()" is there. By the way, this is for controlling something via keyboard, which is why the maxlength is only 1. I want it to be always selected so that when new key are pressed, the last command will be changed without having to use backspace.

    Read the article

  • Javascript Event Bubbling Not Working As Expected

    - by Dean Bayley
    Hi Guys, Having a nightmare trying to figure out event Bubbling.. Example here: link text From what i understand clicking in the area inside the red border should trigger all 3 event handlers (red, blue & body), only red and body are triggered.. I have tried altering the third value of addEventListener and changing the return values but to no avail, any ideas? D.

    Read the article

  • PHP/Javascript - get php variable within javascript

    - by McNabbToSkins
    I have run into an interesting problem. I am currently developing php page and need to access a php variable within the javascript onload. $(document).ready(function() { var temp = <?php $page_id ?> } is this valid? I know that this might seem weird and not be allowed but I am developing a page that has two popup windows. The windows are created using the same view template and there is no way to distinguish between each other. If I stored a hidden value on the page with information unique to the page like so <input type="hidden" value="<?php $page_id ?> id="page_id" /> if there are two views open at the same time there is no way for me to get a unique page id like so var temp = $("#page_id").val(); Because there are two views witht he same input id that is not unique. Long story short is it valid to reference a php variable in the javascript.

    Read the article

  • Are event handlerss in JavaScript called in order?

    - by musicfreak
    I know this is a simple question, but I haven't had the chance to test it in any browser other than Firefox. If I attach multiple event handlers to a single event on a single DOM element, are the event handlers guaranteed to be called in the order they were added? Or should I not rely on this behavior?

    Read the article

  • 3d user experience with HTML5 and Javascript

    - by chako
    I've to build a 3D user experience with HTML5 and any required JS library which provides such functionality. 3D scene consists of a cylindrical pipe and surface. It has 360 degree rotation and can zoom in and out. As user selects a parameter, specific value of that parameter at various depth of pipe in surface should display. I've searched for HTML5 3d and JS libraries and found three.js could help for this.Also found this useful presentation on HTML 3d engine: http://projects.mariusgundersen.net/OnGameStart/#1 .But as this is my first time with HTML5 3d modeling, how should I initiate to build ? What parameters should be considered ? Which tools and libraries would best fit for such requirements ? I would like to create a 3d model using HTML5 and JS 3d engine as shown in the 1st image.

    Read the article

  • javascript: capturing load event on LINK

    - by pgn
    hello everyone, i'm trying to attach an event handler to the load event of a link tag, to execute some code after a stylesheet has loaded. new_element = document.createElement('link'); new_element.type = 'text/css'; new_element.rel = 'stylesheet'; new_element.href = 'http://domain.tld/file.css'; new_element.addEventListener('load', function() { alert('foo'); }, false); document.getElementsByTagName('head')[0].appendChild(new_element) i have tried onreadystatechange as well new_element.onreadystatechange = function() { alert('foo'); } unfortunately neither approach results in an alert being triggered.. Furthermore, new_element.onload is null after registering a handler for the 'load' event with addEventListener.. is that normal? thanks, andrew ps: i may not use any framework in solving this

    Read the article

  • Thread-safe queue in Javascript or jQuery

    - by at
    I have many asynchronous AJAX calls whose results will get processed. It doesn't matter what order the processing occurs, but the results need to get processed one at a time. So I'd like to simple do my AJAX calls and they all just put their results in a single queue. That queue should then get processed on a single thread. This way the results get processed one at a time as soon as possible. What's the best way to do this? I'm using jQuery, so happy to take advantage of any facilities it provides for this.

    Read the article

  • Javascript Object.Watch for all browsers?

    - by SeanW
    Hey all, I was looking for an easy way to monitor an object or variable for changes, and I found Object.Watch that's supported in Mozilla browsers, but not IE. So I started searching around to see if anyone had written some sort of equivalent. About the only thing I've found has been a jQuery plugin (http://plugins.jquery.com/files/jquery-watch.js.txt), but I'm not sure if that's the best way to go. I certainly use jQuery in most of my projects, so I'm not worried about the jQuery aspect... Anyway, the question: can someone show me a working example of that jQuery plugin? I'm having problems making it work... Or, does anyone know of any better alternatives that would work cross browser? Thanks! Update after answers: Thanks everyone for the responses! I tried out the code posted here: http://webreflection.blogspot.com/2009/01/internet-explorer-object-watch.html But I couldn't seem to make it work with IE. The code below works fine in FireFox, but does nothing in IE. In Firefox, each time watcher.status is changed, the document.write in watcher.watch is called and you can see the output on the page. In IE, that doesn't happen, but I can see that watcher.status is updating the value, because the last document.write shows the correct value (in both IE and FF). But, if the callback function isn't called, then that's kind of pointless... :) Am I missing something? var options = {'status': 'no status'}, watcher = createWatcher(options); watcher.watch("status", function(prop, oldValue, newValue) { document.write("old: " + oldValue + ", new: " + newValue + "<br>"); return newValue; }); watcher.status = 'asdf'; watcher.status = '1234'; document.write(watcher.status + "<br>");

    Read the article

  • javascript library to display / animate 3d objects?

    - by saturation
    Hi, I have saw some time ago library where you can import your 3d objects and it will draw those out. You could also animate the objects. The webpage itself was back and there were rotating gear at the corner... Can anyone recall the name of the library? Also you can mention if you know some other neat js libraries. Thanks!

    Read the article

  • JavaScript function pass-through?

    - by Lance May
    I'm not sure if this is doable, but I would like to be able to set a jQuery UI event as a function (directly), as opposed to continuing to wrap in additional function(event, ui) { ... } wrappers. Hopefully you can see what I'm going for from the example below. Here is what I would like: $("#auto").autocomplete({ source: "somepage.php", select: dropdownSelect, minLength: 0 }); Now I would think that the above would work, since I'm simply trying to say "continue firing this event, just over to that function". Unfortunately, that will not work, and I'm ending up with this: (and for some reason, a disconnect from all data) $("#auto").autocomplete({ source: "somepage.php", select: function(event, ui) { dropdownSelect(event, ui) }, minLength: 0 }); Thanks much in advance.

    Read the article

< Previous Page | 6 7 8 9 10 11 12 13 14 15 16 17  | Next Page >