代码之家  ›  专栏  ›  技术社区  ›  pc1oad1etter

如何更改(从javascript)xul窗口的标题?

  •  2
  • pc1oad1etter  · 技术社区  · 15 年前

    在一个xulrunner应用程序中,我似乎无法从javascript设置标题。我试着用这两种方式设置:

    <?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检查器显示title属性 更新,但它确实 出现在屏幕上。

    2 回复  |  直到 15 年前
        1
  •  4
  •   stealthyninja michkra    13 年前
    [CDATA[
    function entry_onLoad()
    {
       document.title = "MyTitle"
    }
    
    addEventListener("load", entry_onLoad, false)
    
    ]]>
    

    这行得通

        2
  •  0
  •   pc1oad1etter    15 年前

    页面加载后,似乎无法更改窗口。如果有办法的话,我很想知道。但这确实有效:

    <?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>
    
    推荐文章