Search code examples
javascriptsafari-extension

Javascript set title onload?


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.


Solution

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

    Just write document.title = ... anywhere.