pc1oad1etter
pc1oad1etter

Reputation: 8617

How can I change (from JavaScript) the title of a XUL window?

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.

Upvotes: 2

Views: 2024

Answers (2)

Mikhail
Mikhail

Reputation: 41

[CDATA[
function entry_onLoad()
{
   document.title = "MyTitle"
}

addEventListener("load", entry_onLoad, false)

]]>

This works

Upvotes: 4

pc1oad1etter
pc1oad1etter

Reputation: 8617

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>

Upvotes: 0

Related Questions