开发者

Javascript set title onload?

Is there anyway to set th开发者_开发技巧e title of a website via JS onload? I wrote this but I'm not sure where it's incorrect:

function my_code(){
document.title = "The new title goes here.";
}

window.onload=my_code();

The page title is static by the way.

Edit: The reason why I want to do it this way is because I'm writing a Safari Extension for a website that does not include tags so I wanted to insert one via JS.


You don't need to wait for the load event.

Just write document.title = ... anywhere.


If you want to change the title after the page loaded, you have to assign a function reference to onload (your function assigns the return value of my_code):

window.onload = my_code;

However, you most certainly can set the title without waiting for the load event.

I'm not familiar with Safari extensions, but you should also make sure that window actually refers to the page's window.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜