logga


2 search engines and flash

One of the biggest arguments against flash is problems with search engines. The content of the swf is not searchable. After some search I found this text that suggest that you should use the swfobject-replace-div-tag to place the content in and then load the flash. The search engines indexes the text and everyone is happy. You can even style it if you want with css.

The problem with this is that you loads the content twice. One when you load the html and one time when you loads the swf. Thats not a big problem since the files are often small and everyone has a fast connection, but its not nice. I made this javascript thats takes the content och the div-tag and sends it to the swf as a flashvar. Another great thing about this is that you dont have to wait until the xml i loaded since its already there in _root.texts. One limitation to this approach is the 65kb -limit on flashvars, but that is a lot of xml.

Before it send the text it replaces the div tags to simpler xml-nodes. Div tags are used in the replace-div to make the html valid xhtml. The class attribute is used to store the note name and the id is kept as a id-attribute.

<div id="swf">
<div class="text" id="text2">This is a two
line text, åäö å</div>
<div class="choice" id="useFlash">true</div>
</div>
<script type="text/javascript">
// <![CDATA[

var div_id = "swf";
var div_txt = document.getElementById(div_id).innerHTML;
var xml_txt = div_txt.replace(/<div class=\"(\w+)\" id=\"(\w+)\">([^<]*)<\/div>/g, "<$1 id=\'$2\'>$3</$1>");
var so = new SWFObject("flash.swf", "flashmovie", "400", "200", "8", "#FFFFFF");
so.addVariable("texts", "<root>"+xml_txt+"</root>");
so.write(div_id);
// ]]>
</script>

the result i can be shown below, its only an example, the code is not used in the example due to wordpress editing possibilities. A plugin has to be written to make it possible to use.

The flash only contains a textfield and the code
txt.htmlText = unescape(_root.texts);

There is a bug somewhere with special characters as åäö. They are not sent to the swf even if utf-8 is used. I have to investigate that further. [update: found a solution, see comment below ]

2 Comments to “search engines and flash”
  1. Gobias, on February 5th, 2008 at 13:14:40, said:

    “There is a bug somewhere with special characters as åäö. ”
    What happens if you uses
    “System.useCodepage = true;”?

  2. admin, on February 15th, 2008 at 15:09:50, said:

    System.useCodepage didn’t solve the problem, other strange characters came instead. But I solved it when I removed the escape() and replaced all attribute name ” with ‘. I don’t understand everything there but it works. The rest has to be valid xml.

Comment on this post below


You can leave a response, or trackback from your own site.