tags:

views:

540

answers:

3

In a xulrunner app, I seem to be unable to set the title from JavaScript. I have tried setting in these two ways:

<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<window id="mywindow" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" onload="go();">

    <!-- your code here -->
<script type="application/x-javascript">
<![CDATA[
    function go(){
        document.getElementById("mywindow").title="blar";
        document.getElementById("mywindow").setAttribute("title","blar");
    }
]]>
</script>
</window>

DOM Inspector shows that the title attribute does get updated, but it does not show up on screen.

A: 

It appears that after the page loads one cannot change the window. If there is a way, I'd be interested to know it.. but this does work:

<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<window id="mywindow" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" >
    <script type="application/x-javascript">
<![CDATA[
    function go(){
        document.getElementById("mywindow").title="blar";
    }
    go();
]]>
</script>
</window>
pc1oad1etter
+1  A: 

The title is not really displayed by window, but by #document which gets it from window. The problem is that when the script is run window is being generated, but document is not finished getting it's values from window. So you need to delay the script to after window is created and change #document's title directly instead :

<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<window id="mywindow" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" title="test">
    <script type="application/x-javascript">
<![CDATA[
    function go(){
        document.title = "blar";
    }
    setTimeout("go()", 10);
]]>
</script>
</window>

You may need to change the timeout from 10 to whatever suits your application best.

Btw. I tested using firefox, but I would figure the same code works (if not better) for xulrunner.

lithorus
A: 
Mikhail