<?xml version="1.0" encoding="utf-8" ?>

<rss version="2.0" 
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:admin="http://webns.net/mvcb/"
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
   xmlns:wfw="http://wellformedweb.org/CommentAPI/"
   xmlns:content="http://purl.org/rss/1.0/modules/content/"
   >
<channel>
    <title>This site works best in a real browser - Cross-Browser</title>
    <link>http://grahamcox.co.uk/serendipity/</link>
    <description>My little place on the web...</description>
    <dc:language>en</dc:language>
    <generator>Serendipity 1.5.3 - http://www.s9y.org/</generator>
    <pubDate>Thu, 03 Aug 2006 15:55:03 GMT</pubDate>

    <image>
        <url>http://grahamcox.co.uk/serendipity/templates/default/img/s9y_banner_small.png</url>
        <title>RSS: This site works best in a real browser - Cross-Browser - My little place on the web...</title>
        <link>http://grahamcox.co.uk/serendipity/</link>
        <width>100</width>
        <height>21</height>
    </image>

<item>
    <title>Caret Position in a text control</title>
    <link>http://grahamcox.co.uk/serendipity/index.php?/archives/13-Caret-Position-in-a-text-control.html</link>
            <category>Code Snippets</category>
            <category>Cross-Browser</category>
    
    <comments>http://grahamcox.co.uk/serendipity/index.php?/archives/13-Caret-Position-in-a-text-control.html#comments</comments>
    <wfw:comment>http://grahamcox.co.uk/serendipity/wfwcomment.php?cid=13</wfw:comment>

    <slash:comments>2</slash:comments>
    <wfw:commentRss>http://grahamcox.co.uk/serendipity/rss.php?version=2.0&amp;type=comments&amp;cid=13</wfw:commentRss>
    

    <author>nospam@example.com (Graham Cox)</author>
    <content:encoded>
    Once again, IE proves that it can&#039;t do anything in a standard way. &lt;br /&gt;
&lt;br /&gt;
Retrieving the caret position from a text control in Firefox and Opera is a very simple job - you simply use the selectionStart and selectionEnd parameters of the control itself.&lt;br /&gt;
&lt;br /&gt;
Retrieving the caret position from a text control in IE is not quite so simple. There are no parameters that give you this information, so you have to work it out for yourself. As it happens, there are a number of ways of doing this available on the internet. Unfortunatly, none of them work properly.&lt;br /&gt;
&lt;br /&gt;
The &quot;official&quot; method of doing it according to the Microsoft Web Team in the article &lt;a href=&quot;http://grahamcox.co.uk/serendipity/exit.php?url=aHR0cDovL21zZG4ubWljcm9zb2Z0LmNvbS9saWJyYXJ5L2RlZmF1bHQuYXNwP3VybD0vbGlicmFyeS9lbi11cy9kaHRtbHRlY2hjb2wvY29scy9kbndlYnRlYW0vd2VidGVhbTEyMDMyMDAxLmFzcA==&amp;amp;entry_id=13&quot; title=&quot;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dhtmltechcol/cols/dnwebteam/webteam12032001.asp&quot;  onmouseover=&quot;window.status=&#039;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dhtmltechcol/cols/dnwebteam/webteam12032001.asp&#039;;return true;&quot; onmouseout=&quot;window.status=&#039;&#039;;return true;&quot;&gt;Yule Not Want to Miss this One&lt;/a&gt; (See &quot;O Cursor, Where Art Thou—finding yourself in a text box&quot;) is just horrible:&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;Save the input field value in a temporary variable. &lt;/li&gt;&lt;li&gt;Create a TextRange object on the document.selection (assuming the input field is focused). &lt;/li&gt;&lt;li&gt;Insert a “~” character into that TextRange object (range.text = &quot;~&quot;). Thus, the tilde would be inserted at the caret position (which we actually want to determine). &lt;/li&gt;&lt;li&gt;Search for the “~” character in the input field value and remember the index where it was found. &lt;br /&gt;
Restore the original input field value, saved at (1). &lt;/li&gt;&lt;li&gt;Return the index determined at (4) and claim it is the caret position.&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;
&lt;br /&gt;
The better method of doing it uses undocumented features of the Range object, and is &lt;a href=&quot;http://grahamcox.co.uk/serendipity/exit.php?url=aHR0cDovL3d3dy5iYXpvbi5uZXQvbWlzaG9vL2FydGljbGVzLmVwbD9hcnRfaWQ9MTI5Mg==&amp;amp;entry_id=13&quot; title=&quot;http://www.bazon.net/mishoo/articles.epl?art_id=1292&quot;  onmouseover=&quot;window.status=&#039;http://www.bazon.net/mishoo/articles.epl?art_id=1292&#039;;return true;&quot; onmouseout=&quot;window.status=&#039;&#039;;return true;&quot;&gt;described here by Mishoo&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
This uses the Range.getBookmark() function which returns a value that can be used to get to the caret position. It worked fine. And in IE7 it stopped working. Microsoft changed the way this function worked (It&#039;s undocumented and so they can do that) and broke things that rely on it.&lt;br /&gt;
&lt;br /&gt;
The third method of working out the caret position, which I have not seen mentioned anywhere on the internet and so might very well not work properly, is to use the Range.offsetLeft value. This gives you a value which represents the distance from the start of the text field that the caret is located at. In standard mode, this value is (position * 7) + 1. &lt;br /&gt;
&lt;br /&gt;
This has been tested in IE5, IE5.5, IE6 and IE7 and returns the same values across all of them. It also returns the same value regardless of the zoom of the page and the location of the textbox on the screen.&lt;br /&gt;
&lt;br /&gt;
As such, below is my cross-browser function to get the caret position from a given text field. It is known to work in Firefox, Opera, Netscape and (now) all versions of IE from 5.5 and up. &lt;br /&gt;&lt;a href=&quot;http://grahamcox.co.uk/serendipity/index.php?/archives/13-Caret-Position-in-a-text-control.html#extended&quot;&gt;Continue reading &quot;Caret Position in a text control&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Fri, 21 Jul 2006 10:23:52 +0100</pubDate>
    <guid isPermaLink="false">http://grahamcox.co.uk/serendipity/index.php?/archives/13-guid.html</guid>
    
</item>
<item>
    <title>IE7 Keyboard entry woes</title>
    <link>http://grahamcox.co.uk/serendipity/index.php?/archives/12-IE7-Keyboard-entry-woes.html</link>
            <category>Coding</category>
            <category>Cross-Browser</category>
    
    <comments>http://grahamcox.co.uk/serendipity/index.php?/archives/12-IE7-Keyboard-entry-woes.html#comments</comments>
    <wfw:comment>http://grahamcox.co.uk/serendipity/wfwcomment.php?cid=12</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://grahamcox.co.uk/serendipity/rss.php?version=2.0&amp;type=comments&amp;cid=12</wfw:commentRss>
    

    <author>nospam@example.com (Graham Cox)</author>
    <content:encoded>
    It seems that IE7 have managed to make things even worse in the cross-browser keyboard handling arena.&lt;br /&gt;
&lt;br /&gt;
From some simple testing, it would appear that either IE7 updates the caret position &lt;strong&gt;before&lt;/strong&gt; the keypress event is triggered, even though the new character isn&#039;t yet entered (and might not be entered), or (and this is more likely) the caret positions are now 1-indexed and not 0-indexed like everybody else uses.&lt;br /&gt;
&lt;br /&gt;
For the vast majority of cases out there, this is not going to cause any problems at all, but if you do care about where the character being entered is meant to go in a cross-browser manner then it would appear that you are in trouble. Essentially all it means is that in IE7 your caret positions are always going to be one greater than they are in the other browsers, but it&#039;s enough of a difference to cause problems...&lt;br /&gt;
&lt;br /&gt;
Edit: (See above) It appears that the problem is really that Microsoft changed the undocumented feature that I was using to get the caret position. I was using this because there is no documented way to get at the position that is worth considering. 
    </content:encoded>

    <pubDate>Thu, 20 Jul 2006 17:27:02 +0100</pubDate>
    <guid isPermaLink="false">http://grahamcox.co.uk/serendipity/index.php?/archives/12-guid.html</guid>
    
</item>
<item>
    <title>Cross-Browser event object</title>
    <link>http://grahamcox.co.uk/serendipity/index.php?/archives/9-Cross-Browser-event-object.html</link>
            <category>Code Snippets</category>
            <category>Cross-Browser</category>
    
    <comments>http://grahamcox.co.uk/serendipity/index.php?/archives/9-Cross-Browser-event-object.html#comments</comments>
    <wfw:comment>http://grahamcox.co.uk/serendipity/wfwcomment.php?cid=9</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://grahamcox.co.uk/serendipity/rss.php?version=2.0&amp;type=comments&amp;cid=9</wfw:commentRss>
    

    <author>nospam@example.com (Graham Cox)</author>
    <content:encoded>
    Different browsers handle events in different ways. Unfortunatly, this means that the same function will receive it&#039;s data in different ways on different browsers. From the major three:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Firefox. Event object is passed as parameter to the callback function&lt;/li&gt;&lt;li&gt;Opera. Event object is passed as a parameter to the callback function. Some members of event object have different names&lt;/li&gt;&lt;li&gt;Internet Explorer. No parameters passed to callback function. Event object exists as a global variable(!) instead. Some members of event object have different names.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;
&lt;br /&gt;
Whilst Internet Explorer does use a global variable to store the event object, this is actually less of a problem since the javascript engine is single-threaded. It shouldn&#039;t be possible to have two event handlers for two different events using the same event object. This could change in IE7 or later however, at which time things will likely all stop working in a horrible manner.&lt;br /&gt;
&lt;br /&gt;
This snippit can be called, being passed the event parameter from the event handler, and will return an event object in a standardised way. Note that this is nowhere near finished, and still has a lot of work needed to cover everything. In specific, keyboard handling is very rudimentary (see below) and mouse handling is non-existant.  &lt;br /&gt;&lt;a href=&quot;http://grahamcox.co.uk/serendipity/index.php?/archives/9-Cross-Browser-event-object.html#extended&quot;&gt;Continue reading &quot;Cross-Browser event object&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Mon, 17 Jul 2006 17:34:54 +0100</pubDate>
    <guid isPermaLink="false">http://grahamcox.co.uk/serendipity/index.php?/archives/9-guid.html</guid>
    
</item>
<item>
    <title>Keyboard handling and Opera</title>
    <link>http://grahamcox.co.uk/serendipity/index.php?/archives/8-Keyboard-handling-and-Opera.html</link>
            <category>Cross-Browser</category>
            <category>Opera</category>
    
    <comments>http://grahamcox.co.uk/serendipity/index.php?/archives/8-Keyboard-handling-and-Opera.html#comments</comments>
    <wfw:comment>http://grahamcox.co.uk/serendipity/wfwcomment.php?cid=8</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://grahamcox.co.uk/serendipity/rss.php?version=2.0&amp;type=comments&amp;cid=8</wfw:commentRss>
    

    <author>nospam@example.com (Graham Cox)</author>
    <content:encoded>
    Keyboard handling in Javascript events gives a whole new meaning to &quot;impossible&quot;. It turns out that there is simply no reliable way to do this and still have your code work across the board.&lt;br /&gt;
&lt;br /&gt;
The main problem here turns out to be Opera. Opera, in their ultimate wisdom, have decided that in the &lt;i&gt;keypress&lt;/i&gt; event they will give you the &lt;i&gt;Keyboard code&lt;/i&gt; for function keys, and &lt;i&gt;Character code&lt;/i&gt; for all other keys. The problem is that they give you this code in the same variable in the event object. &lt;br /&gt;
&lt;br /&gt;
The problem comes from the fact that the keyboard code and the character code can, and often do, overlap each other. For example, the character code for the period character is 46. It just so happens that the keyboard code for the delete key is also 46. Having compared the event object that is passed into the keypress event when the period and the delete key are pressed, the event objects are identical. There is not a single way to tell the difference between those two keys in that event!&lt;br /&gt;
&lt;br /&gt;
As it happens, the reason I was trying to do this was to have a text field that only allows certain keys to be pressed. Period wasn&#039;t one of the keys, but I did want all the function keys to work (arrows, delete, home, end, etc). Another &quot;feature&quot; of Opera is that these keys can not be cancelled. As such, if I think it might be a period I can try and cancel it, and if it&#039;s a period it&#039;s cancelled and if it&#039;s a delete then it&#039;s not. 
    </content:encoded>

    <pubDate>Mon, 17 Jul 2006 13:52:31 +0100</pubDate>
    <guid isPermaLink="false">http://grahamcox.co.uk/serendipity/index.php?/archives/8-guid.html</guid>
    
</item>
<item>
    <title>Cross-Browser getElement()</title>
    <link>http://grahamcox.co.uk/serendipity/index.php?/archives/7-Cross-Browser-getElement.html</link>
            <category>Code Snippets</category>
            <category>Cross-Browser</category>
    
    <comments>http://grahamcox.co.uk/serendipity/index.php?/archives/7-Cross-Browser-getElement.html#comments</comments>
    <wfw:comment>http://grahamcox.co.uk/serendipity/wfwcomment.php?cid=7</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://grahamcox.co.uk/serendipity/rss.php?version=2.0&amp;type=comments&amp;cid=7</wfw:commentRss>
    

    <author>nospam@example.com (Graham Cox)</author>
    <content:encoded>
    This code is a simple Javascript function that works in most modern browsers to return a document element given the name of the element.

It requires that both the name and id attribute of the control be set to the same value, and this value is what is used to look up the element. 
 &lt;br /&gt;&lt;a href=&quot;http://grahamcox.co.uk/serendipity/index.php?/archives/7-Cross-Browser-getElement.html#extended&quot;&gt;Continue reading &quot;Cross-Browser getElement()&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Mon, 17 Jul 2006 13:42:55 +0100</pubDate>
    <guid isPermaLink="false">http://grahamcox.co.uk/serendipity/index.php?/archives/7-guid.html</guid>
    
</item>
<item>
    <title>What &quot;Cross-Browser&quot; really means</title>
    <link>http://grahamcox.co.uk/serendipity/index.php?/archives/6-What-Cross-Browser-really-means.html</link>
            <category>Cross-Browser</category>
    
    <comments>http://grahamcox.co.uk/serendipity/index.php?/archives/6-What-Cross-Browser-really-means.html#comments</comments>
    <wfw:comment>http://grahamcox.co.uk/serendipity/wfwcomment.php?cid=6</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://grahamcox.co.uk/serendipity/rss.php?version=2.0&amp;type=comments&amp;cid=6</wfw:commentRss>
    

    <author>nospam@example.com (Graham Cox)</author>
    <content:encoded>
    One of the good things about Javascript is that it runs on any web browser that has support for it. This means that you can write your code and know that anyone with a recent enough browser can run it and benefit from it.&lt;br /&gt;
&lt;br /&gt;
One of the bad things about Javascript is that it runs on any web browser, and that the people who write web browsers rarely do things the same as each other. This means that your code that works perfectly on &lt;a href=&quot;http://grahamcox.co.uk/serendipity/exit.php?url=aHR0cDovL3d3dy5nZXRmaXJlZm94LmNvbQ==&amp;amp;entry_id=6&quot; title=&quot;http://www.getfirefox.com&quot;  onmouseover=&quot;window.status=&#039;http://www.getfirefox.com&#039;;return true;&quot; onmouseout=&quot;window.status=&#039;&#039;;return true;&quot;&gt;Firefox&lt;/a&gt; will likely totally fail to run at all on Internet Explorer, or &lt;a href=&quot;http://grahamcox.co.uk/serendipity/exit.php?url=aHR0cDovL3d3dy5vcGVyYS5jb20=&amp;amp;entry_id=6&quot; title=&quot;http://www.opera.com&quot;  onmouseover=&quot;window.status=&#039;http://www.opera.com&#039;;return true;&quot; onmouseout=&quot;window.status=&#039;&#039;;return true;&quot;&gt;Opera&lt;/a&gt;, or whichever browser you want to use.&lt;br /&gt;
&lt;br /&gt;
Because of this, it becomes very difficult to write powerful Javascript applications that are going to work for even the majority of users, and (almost) impossible to write them so that they will work for all users.  
    </content:encoded>

    <pubDate>Mon, 17 Jul 2006 13:39:14 +0100</pubDate>
    <guid isPermaLink="false">http://grahamcox.co.uk/serendipity/index.php?/archives/6-guid.html</guid>
    
</item>

</channel>
</rss>