Jump to content

tinfanide

Members
  • Posts

    445
  • Joined

  • Last visited

Everything posted by tinfanide

  1. No, I meant the codes in your first thread worked in my IE8. Not you newest findings. This meant there should have not been a problem posted by you on my machine.Anyway, glad ya finally got it solved.
  2. Even with your old codes, it works in my IE8 (IE9 compatibility mode).Go to this testing page and have a look:http://lifelearning.x10.mx/test/testing.html
  3. I couldn't track the version of the codes you have seen no error returning and whether that is the same to mine at present.Now my altered codes work in FF14:// php_slides.js var sJSON, xmlhttp;var ajax = function(action,method,source,async){xmlhttp = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP") ? new ActiveXObject("Msxml2.XMLHTTP") : null ; // I have moved this section before the onreadystatechange function// previously this section was after the onreadystatechange function, which it didn't workxmlhttp.open(method,source,async);xmlhttp.send();// xmlhttp.onreadystatechange = function(){ if (this.readyState == 4 && this.status == 200) { sJSON = (String(source).toLowerCase().substr(String(source).length-5,String(source).length)==".json") ? JSON.parse(this.responseText) : (String(source).toLowerCase().substr(String(source).length-4,String(source).length)==".txt") ? this.responseText : null; action(); }};} It still returns this error in the console when you use FF14 to browse to php_slides.json, though:
  4. The page still doesn't show the texts in mouse scrolling.Mine is Firefox Portable 14.0.1. Does it matter? I didn't get the error. On the contrary, I still get the error as stated in my first thread:
  5. I don't know if I have posted this question in a right area here. Yet it's about AJAX and JSON, I treat it as a JavaScript's one. My question is:Firefox 13.0.1 and IE7+ do not return this error message produced by the console when I open the JSON (stored online) file in the browser: And when you visit this website (a testing website of mine),http://lifelearning.x10.mx/test/php_slides.htmland scroll your mouse within the div (surrounded by the black border),the texts do not come out expectedlly (which otherwise do in any browsers listed above except FF14). I would like to ask how I can declare the character encoding of a plain text as requested by the FF14 web console. Many thanks in advance.
  6. I have a websitehttp://lifelearning.x10.mx/test/t.htmlwhich returns a string from a server text file loaded by AJAX. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Untitled Document</title><script src="json2.js"></script><script src="php_slides.js"></script><script>window.onload = function(){ajax(function(){ document.getElementById("SlideLink").innerHTML = sJSON; },"GET","php_slides.txt",true);}</script></head><body><textarea id="SlideLink"></textarea></body></html>// php_slides.jsvar sJSON, xmlhttp;var ajax = function(action,method,source,async){xmlhttp = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP") ? new ActiveXObject("Msxml2.XMLHTTP") : null ;xmlhttp.onreadystatechange = function(){ if (this.readyState == 4 && this.status == 200) { sJSON = JSON.parse(this.responseText); action(); }};xmlhttp.open(method,source,async);xmlhttp.send(null);} The text file:http://lifelearning.x10.mx/test/php_slides.txt The returned string is the one with the double quotes removed.How could I have the string completely returned by AJAX?
  7. Yes. It works.Thanks for you all discussing this code. <script type="text/javascript" src="a.js"></script><script> // passing a function does not need quotes ("")func(f);function f(){alert("this is a function.");}</script> // a.jsfunction func(a){ // It seems that after loading the HTML document, loading the js file precedes loading the document.body. // It seems that that's why document.body is null when loading this js file document.onmousedown = a;}
  8. So it is never possible to do this way?
  9. This doesn't work.I think the problem mainly lies in the a.js filewheredocument.body returns null (of course there is no document.body within the a.js file) It seems that I cannot store the mouse event in a seperate JS file.
  10. <script type="text/javascript" src="a.js"></script><script>func("f");function f(){alert("this is a function.");}</script> // a.jsfunction func(a){document.body.onmousedown = a;} I want to pass "f" to the handler in the file a.js.But it says
  11. I'm not sure if I have understood from your words or not:var evt = (!document.all) ? "DOMMouseScroll" : "onmousewheel" ;if(document.attachEvent){document.attachEvent(evt,f);}else if(document.addEventListener){document.addEventListener(evt,f,false);}function func(e) // the parameter "e" is passed to the "e" below{ evt = window.event || e; // this "e" is used by Firefox delta = (evt.detail) ? evt.detail*-120 : evt.wheelDelta; return delta;}function f(e){alert(func(e));} In my previous not working codes, the parameter in func() is not the same to the evt variable (e);Andin the function f, the event should be passed to the function func within the function f. Anyway, the above codes should work in both IE and FF.
  12. Yes, millions of years ago a decent guy here took me to a good reference to getComputedStyle():http://www.sophox.com/wordpress/?p=759His reference really helps a lot. This reminds me of that, then.
  13. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Untitled Document</title><script>var evt = (!document.all) ? "DOMMouseScroll" : "onmousewheel" ;if(document.attachEvent){document.attachEvent(evt,func);}else if(document.addEventListener){document.addEventListener(evt,func,false);} //if(document.attachEvent){document.attachEvent(evt,f);}else if(document.addEventListener){document.addEventListener(evt,f,false);}//function func(evt){if(!evt){evt = window.event}// evt = window.event || e;delta = (evt.detail) ? evt.detail*-120 : evt.wheelDelta;return delta;}function f(evt){alert(func());}</script></head><body></body></html> I have attached the f function to the document. It works in IE but in FF9, it says evt is undefined.
  14. var evt, delta, d;function show(e){evt = window.event || e;delta = (evt.detail) ? evt.detail*(-120) : evt.wheelDelta ;delta = (delta>0) ? delta/delta : (delta/delta)*-1 ;return delta;}var move = (!document.all) ? "DOMMouseScroll" : "onmousewheel" ;if(document.attachEvent){document.attachEvent(move,show);}else if(document.addEventListener){document.addEventListener(move,show,false);} window.onload = function(){console.log(show());} I want the show function to return the mousescroll value to be used in another function.But it returns evt being undefined (in the debugger).
  15. Yes, understood.But the need is without setting the values in JS, JS should get the values itself from CSS. Here's the fix:// Reference from:// http://www.quirksmode.org/js/findpos.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Untitled Document</title><script>window.onload = function(){alert(ElementPosition("div")["currentLeft"]);}function ElementPosition(oID){obj = document.getElementById(oID);var curLeft = curTop = 0;if (obj.offsetParent){ do { curLeft += obj.offsetLeft; curTop += obj.offsetTop; } while (obj = obj.offsetParent);}return {"currentLeft":curLeft,"currentTop":curTop};}</script><style type="text/css">#div{width: 100px; height: 100px;position: absolute; left: 50px; top: 200px;background-color: #000000;}</style></head><body><div id="div"></div></body></html> The fix is not perfect, though. People say the offset property is not fully supported in IE8-.Tested in IE7, 8, 9 and FF9. Passed.I am not good with compatibility issue.
  16. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Untitled Document</title><script>var timer;window.onload = function(){// if the position left and top are not set in JS// the function move cannot alter the left value/*document.getElementById("div").style.left = 0;document.getElementById("div").style.top = 0;*/document.getElementById("div").onmouseover = move;document.getElementById("div").onmouseout = function(){ clearTimeout(timer);};}function move(){clearTimeout(timer);document.getElementById("div").style.left = parseInt(document.getElementById("div").style.left) + 1 + "px";timer = setTimeout(move,10);}</script><style>#div{position: relative; left: 10px; top: 10px;width: 1200px; height: 400px;}.images{width: 400px; height: 400px;float: left;}</style></head><body><div id="div"><img class="images" src="1.jpg" /><img class="images" src="2.jpg" /><img class="images" src="3.jpg" /></div></body></html> I don't understand the question raised in the comment block.Please help.Thanks.
  17. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Untitled Document</title><script>window.onload = function(){ document.getElementById("txt").onkeypress = function(evt){ var evt = (evt) ? evt : ( (event) ? event : null ) ; var elem = (evt.target) ? evt.target : ( (evt.srcElement) ? evt.srcElement : null ) ; if((evt.keyCode == 13) && (elem.type == "text")) { document.getElementById("t").focus(); return false; }}}function c(){alert(document.getElementById("txt").value);}</script></head><body><form name="form" id="form" onchange="c();"><input id="t" type="input" value="t"/><input id="txt" type="input" value=""/><input id="t2" type="input" value="t2"/></form></body></html> The onChange event is only fired in IE9, not IE7 or IE8.
  18. Of course I knew the difference between them.Anyway, just handled the ENTER keypress event.But just it works in FF and IE9 but not IE7 and IE8.Why is compatibility always a problem?
  19. Yes, I knew it is default. Just wondered why it had been exceptional before it suddenly turned to be default.Anyway, if I stick to the form approach instead of the textarea fields, do I need to handle the onkeypress event like this (what I did in the codes of the page) document.forms["form"].onsubmit = function(){return false;} But if so, it disables the submit function which sends data to a PHP page.
  20. Please kindly go tohttp://lifelearning....st.com/lib.htmlA testing page. I use FF9 for testing the page. The page used to be something likewhen users press enter when the input box is focused.It only triggered the onchange event attached to the form. But now, (please see the source code of the testing page)I have to use return false to disable the submit event.Without doing so, it just submits without triggering the onchange event. Is there a possibility where enter will not trigger the submit eventbutthe onchange event?
×
×
  • Create New...