Tutorials to .com

Tutorials to .com » Dotnet » Foundation » How perfect Web development control IE title bar

How perfect Web development control IE title bar

Print View , by: iSee ,Total views: 18 ,Word Count: 1102 ,Date: Thu, 20 Aug 2009 Time: 9:59 PM

As well as any current IE browser title bar, which should be by <title> to control the HTML tags, of course, still is. Only the current trend is a ghost, you'd better not to update your web pages, and then also need to receive the user's arbitrary torn. This is the legendary Dragon not see the end of the first murder on the contrary, when invisible Ajax technology!

In the browser's title bar shows the appropriate page titles, is a professional web site performance, but also search engine friendly. Of course, if placed on the appropriate message will be meaningful. Well, how "dynamic" to customize the title of the content?

We know that the use of modified asp dynamic browser title, something like this statement:

<title> <% = GenerateTitle%> </ title>

In ASP.NET 1.1, in addition to still be able to use the method above, we have one more look "beautiful" approach:

In aspx page:
<title id="cltTitle" runat="server"> </ title>
In CS file:
protected HtmlGeneralControl cltTitle;
...
cltTitle.innerHtml = "birdshome's homepage";

Today, the ASP.NET 2.0 era, in addition to the above two methods, we can more easily modify the content <title>:

Page.Title = "birdshome's homepage";

But the above "dynamic" in the server-side <title> modify the content, in fact, the browser is the content of labels <title> is completely fixed by. Closer to home the following carefully is that the client browser to the IE title bar of the control:

IE window for the page, the page DOM object, document.title attribute is used to replace the innerHTML element <title> access IE window and set the contents of the title bar. See the following examples:

<html>
<body>
<! - Page content ->
<script language=" JavaScript ">
document.body.onload = function ()
(
document.title = "birdshome's homepage";
);
</ script>
</ body>
</ html>

Right, is as simple as you can set up general IE window title bar. So what's it say? If we compare this time the code is identical to the modal window enforced? Modal window title bar will be changed? The results are frustrating, and this exactly the same code, in the modal window on a failure. Is the window modal and ordinary DOM provided a window different? In fact, the modal window and DOM is the same as ordinary window, and the difference is that when the modal window after the completion of page load, document.title attribute failure indeed. That is why in the above sample code in the onload event reasons for invalid statement. Address this limitation is simple, it is necessary to load the page has not been completed on the amendment of document.title, so modified modal IE window title bar on the result of the use of such a code:

<html>
<body>
<! - Page content ->
<script language="javascript">
document.title = "birdshome's homepage";
</ script>
</ body>
</ html>

The following is included in both a modified method of the browser title bar of the sample, save it as a "abc.htm" document, you can use to open IE to see the difference between a very intuitive:

<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 an ordinary window title bar of IE from the "birdshome's homepage (first)" to fast "birdshome's homepage (rewrite)", and use the Open button to open the title of modal dialog box will always be "birdshome's homepage (first) . " In this example we can see that, as an ordinary IE window, the title bar is the survival of the page to modify any time. The modal window title bar, we can only be loaded before the completion of its page (onload event to trigger the former) can be modified. Modeless dialog box, opend by showModelessDialog, the title bar for the treatment and the same modal dialog box.

Document.title final say in the use of a skill, we know that if the server side "dynamic" to amend title page, we can assure <title> </ title> tags between the title bar write &nbps; generated in continuous space the effect of cell input. This technique in the window mode is particularly useful, so we can put that nasty "- Web Page Dialog" with the word for the title of column space to the outside. Document.title attributes used to modify the page after the title bar, whether it is an ordinary window or window mode, "" and "" (space) can not, and the former will be directly displayed in the title bar when the string, the latter has only one more to add "" (space) the width of the effect. Here, we have to use another space, entities to solve the problem. 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


.NET foundation Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.