<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Alex Little &#187; javascript</title>
	<atom:link href="http://alexlittle.net/blog/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://alexlittle.net/blog</link>
	<description></description>
	<lastBuildDate>Thu, 09 Feb 2012 10:34:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Through the Square (javascript) Window</title>
		<link>http://alexlittle.net/blog/2008/05/22/through-the-square-javascript-window/</link>
		<comments>http://alexlittle.net/blog/2008/05/22/through-the-square-javascript-window/#comments</comments>
		<pubDate>Thu, 22 May 2008 16:32:42 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Web dev & programming]]></category>
		<category><![CDATA[cohere]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://alexlittle.net/blog/?p=373</guid>
		<description><![CDATA[For the Cohere site, I&#8217;ve been trying to figure out how you can keep track of a pop up window using Javascript even when the parent page changes (to another page on same domain) and to know whether the pop up window is already open. I&#8217;m having exactly the problem mentioned in this forum post [...]]]></description>
			<content:encoded><![CDATA[<p>For the Cohere site, I&#8217;ve been trying to figure out how you can keep track of a pop up window using Javascript even when the parent page changes (to another page on same domain) and to know whether the pop up window is already open. I&#8217;m having exactly the problem mentioned in this <a href="http://www.webmasterworld.com/forum91/4865.htm">forum post</a> &#8211; but as yet no solution.</p>
<p>All the example scripts I&#8217;ve found so far will only work if the parent page remains the same. I.e. you&#8217;re testing whether the pop up is already open, but applying this test on the document/page that originally opened the popup. What I&#8217;m looking to do is subtly different &#8211; so the pop up remains open so as you are browsing Cohere you can add ideas to make connections between.</p>
<p>I would think that this ought to be possible, because if you open a popup window with the same name as an existing one, the old one will get overwritten &#8211; so it &#8216;knows&#8217; that the pop up exists. Plus, this is all running from the same domain, so there won&#8217;t be any cross domain issues.</p>
<p>If anyone has any pointers as to how to achieve this, it would be much appreciated. Or if you have other suggestions for how the same results could be achieved. Cheers <img src='http://alexlittle.net/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://alexlittle.net/blog/2008/05/22/through-the-square-javascript-window/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>IE crashing with MSG</title>
		<link>http://alexlittle.net/blog/2007/10/25/ie-crashing-with-msg/</link>
		<comments>http://alexlittle.net/blog/2007/10/25/ie-crashing-with-msg/#comments</comments>
		<pubDate>Thu, 25 Oct 2007 14:36:08 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Web dev & programming]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[ie]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[msg]]></category>
		<category><![CDATA[openlearn]]></category>

		<guid isPermaLink="false">http://alexlittle.net/blog/2007/10/25/ie-crashing-with-msg/</guid>
		<description><![CDATA[Came back from holiday yesterday (see the pics!) , to find a stack of emails about problems with MSG crashing IE. This is a bit odd as we&#8217;ve not updated MSG for a little while, so strange that it just seems to have started occuring. It seems quite an erratic problem, but it does bring [...]]]></description>
			<content:encoded><![CDATA[<p>Came back from holiday yesterday (<a href="http://alexlittle.net/blog/photo.php?ps=34">see the pics</a>!) , to find a stack of emails about problems with MSG crashing IE. This is a bit odd as we&#8217;ve not updated MSG for a little while, so strange that it just seems to have started occuring. It seems quite an erratic problem, but it does bring the whole browser down &#8211; something I find a little odd for a purely javascript application.</p>
<p>I&#8217;m really hoping to get this fixed very soon, but haven&#8217;t yet found the root cause, I can reliable recreate the issue, so just need to find why it&#8217;s happening.</p>
<p>Plus I need to get my presentation for next weeks <a href="http://www.open.ac.uk/openlearn/openlearn2007/conference.php">OpenLearn conference</a> written sometime soon!</p>
<p>Update (29th Oct)&#8230; I have now got the problem resolved, though still don&#8217;t know the real root cause. I fixed it by going back through the changes I&#8217;ve made recently and seeing at what point the error started occuring.<br />
The change which appears to have been causing the error was when I switched from using &lt;a href=&#8221;javascript:&#8230;.&#8221;&gt; to using (what I thought was the proper way!) of adding/removing event listeners. The actual problem occured with the call to detach event, although it didn&#8217;t fail everytime &#8211; it would work for the first few times and then randomly cause the browser to crash. I did notice that the carsh would only happen if I had the MSG client and the referring site (the one with the users presence icon) open at the same time, if only one was open the crash wouldn&#8217;t occur.</p>
<p>For info this was the code that was causing problems:<br />
<code><br />
var oldImg = presenceNode.firstChild;<br />
    //remove any current listeners<br />
    if(oldImg.removeEventListener){ // Mozilla, Netscape, Firefox<br />
    oldImg.removeEventListener('click', launchClick, false);<br />
    oldImg.removeEventListener('click', readMessageClick, false);<br />
	} else { // IE<br />
    oldImg.detachEvent('onclick', launchClick);<br />
    oldImg.detachEvent('onclick', readMessageClick);<br />
	}<br />
</code></p>
<p>So I replaced this with the code below that just alters the location and title of the link (also a bit of adjusting to add the &lt;a&gt; in):<br />
<code><br />
var oldAnchor = presenceNode.firstChild;<br />
    var newAnchor = oldAnchor.cloneNode(true);<br />
 newAnchor.href = "javascript:readMessageClick();";<br />
        newAnchor.title = MSGAPIconf.str_oneMessageUnread;</p>
<p></code><br />
So, glad to have got it fixed, but would be even better to know why this was really happening at all!</p>
<p>Update Number 2 (1st Nov) &#8211; The fix has now been made live on the MSG-OpenLearn servers.</p>
]]></content:encoded>
			<wfw:commentRss>http://alexlittle.net/blog/2007/10/25/ie-crashing-with-msg/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript addEventListener &#8211; peculiarity or bug?</title>
		<link>http://alexlittle.net/blog/2007/09/11/javascript-addeventlistener-peculiarity-or-bug/</link>
		<comments>http://alexlittle.net/blog/2007/09/11/javascript-addeventlistener-peculiarity-or-bug/#comments</comments>
		<pubDate>Tue, 11 Sep 2007 09:01:20 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Web dev & programming]]></category>
		<category><![CDATA[event listener]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://alexlittle.net/blog/2007/09/11/javascript-addeventlistener-peculiarity-or-bug/</guid>
		<description><![CDATA[Yesterday I was writing some javascript code to dynamically produce a list and add an event listener for when an item in the list was clicked on. When I then tested it out, for some reason the last event listener seems to have overridden all the others in the list. I&#8217;m not sure if the [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I was writing some javascript code to dynamically produce a list and add an event listener for when an item in the list was clicked on. When I then tested it out, for some reason the last event listener seems to have overridden all the others in the list. I&#8217;m not sure if the is a Javascript &#8216;feature&#8217; or bug, but it occurs in both Firefox (v2) and IE (v6).<br />
This is the code I tested:</p>
<pre style="font-size:120%">
<code>
function init(){
	var myUl = document.getElementById("test");

	for(var i=0; i&lt;10; i++){
		var myLi = document.createElement("li");
		mySpan = document.createElement("span");
		mySpan.setAttribute("id","myspan"+i);
		myLi.appendChild(mySpan);
		myUl.appendChild(myLi);

		mySpan.appendChild(document.createTextNode(i));
		if(mySpan.addEventListener){ // Mozilla, Netscape, Firefox
			mySpan.addEventListener('click', function(){test(i);}, false);
		} else { // IE
			mySpan.attachEvent('onclick', function(){test(i);});
		}
	}
}

function test(myNum){
	alert(myNum);
}
</code></pre>
<p>This produces an unordered list of 10 items &#8211; (0-9), but when you click on any of the numbers the alert returns &#8217;10&#8242;, rather than the expected 0-9 depending on which on you click. I could understand if it returned &#8217;9&#8242; for every item in the list &#8211; but why 10?? I spent ages fiddling with this, but never did find what was actually causing this to occur &#8211; it seems like a bug to me &#8211; unless I&#8217;m just misunderstanding how the addEventListeners work? Maybe something to do with the fact I&#8217;m using anonymous functions?</p>
<p>If anyone has an explanation (or can point me to an explanation) as to what I&#8217;ve done wrong it would be much appreciated.</p>
<p>For info I managed to get around the problem by using the code below instead, though I&#8217;d still like to know what was wrong with my original code!</p>
<pre style="font-size:120%">
<code>
function init(){
	var myUl = document.getElementById("test");

	for(var i=0; i&lt;10; i++){
		var myLi = document.createElement("li");
		mySpan = document.createElement("span");
		mySpan.setAttribute("id",i);
		myLi.appendChild(mySpan);
		myUl.appendChild(myLi);

		mySpan.appendChild(document.createTextNode(i));
		if(mySpan.addEventListener){ // Mozilla, Netscape, Firefox
			mySpan.addEventListener('click', eventHandler, false);
		} else { // IE
			mySpan.attachEvent('onclick', eventHandler);
		}
	}
}

function eventHandler(e){
	var e=e? e : window.event;
	var el=e.target? e.target : e.srcElement;
	alert(el.id);
}
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://alexlittle.net/blog/2007/09/11/javascript-addeventlistener-peculiarity-or-bug/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Friday 25 August 06</title>
		<link>http://alexlittle.net/blog/2006/08/25/friday-25-august-06-3/</link>
		<comments>http://alexlittle.net/blog/2006/08/25/friday-25-august-06-3/#comments</comments>
		<pubDate>Fri, 25 Aug 2006 15:05:25 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Web dev & programming]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://alexlittle.net/blog/2006/08/25/friday-25-august-06-3/</guid>
		<description><![CDATA[Found a way to replace the alt text &#8211; it involves creating a new element, assigning the required attributes and finally then overwriting the original img tag, here is some sample code: var oldImg = myNode.firstChild; var newImg = document.createElement(&#8216;img&#8217;); newImg.src = &#34;/new/path/to/image/jpg&#34;; newImg.alt = &#34;my new alt text&#34;; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; myNode.replaceChild(newImg,oldImg); Note that this is [...]]]></description>
			<content:encoded><![CDATA[<p>Found a way to replace the alt text &#8211; it involves creating a new element, assigning the required attributes and finally then overwriting the original img tag, here is some sample code:</p>
<p>var oldImg = myNode.firstChild;<br />
var newImg = document.createElement(&#8216;img&#8217;);<br />
newImg.src = &quot;/new/path/to/image/jpg&quot;;<br />
newImg.alt = &quot;my new alt text&quot;;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />
myNode.replaceChild(newImg,oldImg);</p>
<p>Note that this is very basic example and probably only works when &#8216;myNode&#8217; has a single child node which is of type &#8216;img&#8217;.</p>
]]></content:encoded>
			<wfw:commentRss>http://alexlittle.net/blog/2006/08/25/friday-25-august-06-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Friday 25 August 06</title>
		<link>http://alexlittle.net/blog/2006/08/25/friday-25-august-06/</link>
		<comments>http://alexlittle.net/blog/2006/08/25/friday-25-august-06/#comments</comments>
		<pubDate>Fri, 25 Aug 2006 08:27:14 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Web dev & programming]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[moodle]]></category>
		<category><![CDATA[msg]]></category>

		<guid isPermaLink="false">http://alexlittle.net/blog/2006/08/25/friday-25-august-06/</guid>
		<description><![CDATA[With the problems etc I outlined yesterday I&#8217;ve been thinking that we might be trying to make it all overcomplicated by allowing the user to change their presence from within the block &#8211; and all the associated problems this entails with maintaining session ids in Moodle and JavaScript, knowing when they&#8217;ve expired etc. I think [...]]]></description>
			<content:encoded><![CDATA[<p>With the problems etc I outlined yesterday I&#8217;ve been thinking that we might be trying to make it all overcomplicated by allowing the user to change their presence from within the block &#8211; and all the associated problems this entails with maintaining session ids in Moodle and JavaScript, knowing when they&#8217;ve expired etc. I think our best bet would be maybe concentrate on getting &#8216;live&#8217; presences showing in the forums, and just have the Moodle block as a link out to launch the MSG window &#8211; maybe just have the block showing number of online users. So today I think I look into how I can make the no users online appear as a live count and how the users presence can be made &#8216;live&#8217; in the forum display.</p>
]]></content:encoded>
			<wfw:commentRss>http://alexlittle.net/blog/2006/08/25/friday-25-august-06/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 0.674 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2012-02-11 01:52:28 -->

