The title bar of IE and any current browser should originally be controlled by the <title> HTML tag, and of course it still is. It's just that the current ghost trend is that you'd better not refresh your web page anymore, and then you need to accept any ravage from users. This is the legendary paradoxical Ajax technology that kills people without a trace!
Displaying an appropriate page title in the title bar of the browser is a professional expression of a web page and is also friendly to search engines. Of course, it would also be very meaningful if appropriate prompt information is placed. So how to "dynamically" customize the title content?
We know that we can use ASP to dynamically modify the browser title, which is probably a statement like this:
<title><% = GenerateTitle %></title>
In ASP.NET 1.1, in addition to still using the above method, we have one more The "beautiful" way to look:
In aspx page:
<title id="cltTitle" runat="server"></title>
In CS file:
protected HtmlGeneralControl cltTitle;
. . .
cltTitle.innerHtml = "birdshome's homepage";
Today is in the ASP.NET 2.0 era. In addition to the above two methods, we can also modify the <title> content more easily:
Page.Title = "birdshome's homepage";
However, the above "dynamic "The content of <title> is modified on the server side. In fact, for the browser, the content within the <title> tag is completely fixed. Let's get back to the point and let's talk about the control of the IE browser title bar on the client in detail:
For pages in the IE window, in the page DOM object, the document.title attribute is used to replace the innerHTML of the <title> element to get and set IE The content of the window title bar. Consider the following example:
<html>
<body>
<!-- page content -->
<script language="javascript">
document.body.onload = function()
{
document.title = "birdshome's homepage";
};
</script>
</body>
</html>
Yes, it is that simple to set the title bar of an ordinary IE window. So what's there to say? At this time, what if we put the exact same code into the modal window for execution? Will the title bar of the modal window be modified? The results of the experiment were frustrating. The exact same code failed in the modal window. Is the DOM provided by the modal window different from that of the ordinary window? In fact, the DOM of the modal window is the same as that of the ordinary window, but the difference is that after the page in the modal window is loaded, the document.title attribute will indeed become invalid. This is why the statement in the onload event of the example code above has no effect. The way to solve this limitation is very simple, which is to modify the document.title before the page is loaded. Therefore, to modify the IE title bar in the modal window, you should use this code:
<html>
<body>
<!-- page content -->
<script language="javascript">
document.title = "birdshome's homepage";
</script>
</body>
</html>
The following is an example that includes the above two methods of modifying the browser title bar. Save it as an "abc.htm" file. Open it with IE and you can see the difference intuitively:
<html>
<body>
<button onclick="foo()">
Open</button>
<script language="javascript">
document.body.onload = function()
{
document.title = "birdshome's homepage (rewrite)" + unescape(H_A0);
};
document.title = "birdshome's homepage (first)" + unescape(H_A0);
function foo()
{
window.showModalDialog("abc.htm");
}
</script>
</body>
</html>
The result is that the title bar of the ordinary IE window will quickly change from "birdshome's homepage (first)" to "birdshome's homepage (rewrite)", while the title of the modal dialog box opened by using the Open button will always be "birdshome's homepage (first)". From this example we can see that for an ordinary IE window, its title bar can be modified at any time during the page lifetime. As for the title bar of the modal window, we can only modify it before the page is loaded (before the onload event is triggered). The non-modal dialog box, opened by showModelessDialog, handles the title bar exactly the same as the modal dialog box.
Finally, let's talk about a technique in using document.title. We know that if the page title is "dynamically" modified on the server side, we can write &nbps; between the <title></title> tags to generate continuous spaces on the title bar. Enter the effect. This technique is especially useful in modal windows, so that we can push that pesky "-Web Page Dialog" text out of the title bar with continuous spaces. After using the document.title attribute to modify the page title bar, whether it is a normal window or a modal window, " " and " " (space) cannot be used. The former will be displayed directly on the title bar as a string, and the latter No matter how much you add, it will only have the width effect of one " " (space). Here we have to use another space, entity , to solve this problem. The code is as follows:
<html>
<body>
<script language="javascript">
var HexA0s = "%A0 %A0 %A0 %A0";
document.body.onload = function()
{
document.title = "birdshome's homepage (rewrite)" + unescape(HexA0s);
};
</script>
</body>
</html>
http://birdshome.cnblogs.com/archive/2006/06/23/control_browser_title.html