admin管理员组文章数量:1326069
Is there anyway to set the 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.
Is there anyway to set the 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.
Share Improve this question edited Sep 4, 2011 at 17:55 Charlie asked Sep 4, 2011 at 17:48 CharlieCharlie 11.8k19 gold badges87 silver badges140 bronze badges 3- why do you want to do this? the user won't be able to see it. – Daniel A. White Commented Sep 4, 2011 at 17:50
- Why not just put the title in the title tag as normal? – Jamie Dixon Commented Sep 4, 2011 at 17:50
- I'm writing a safari extension that changes a website's layout and there is no title tag, so I wanted my script to add one via JS onload. – Charlie Commented Sep 4, 2011 at 17:50
3 Answers
Reset to default 6You 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
.
solved your question
script:
function load_title(){
var title = document.getElementsByTagName("title")[0];
var text_title = "SUNDAGEEKS ツ The aspiring white-hat hacker/security awareness playground ≪ SUNDAGEEKS :: INDOXPLOIT";
document.title = text_title;
}
var title_js = document.createElement("title");
window.onload = load_title();
document.getElementsByTagName("head")[0].appendChild(title_js);
本文标签: safari extensionJavascript set title onloadStack Overflow
版权声明:本文标题:safari extension - Javascript set title onload? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742195778a2431054.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论