document.write in status bar
I开发者_Python百科'm trying to create my own bookmarklet, and there aren't exactly a huge number of guides for doing so. Basically, right now I'm trying to figure out why I can't just do javascript:document.write("HAI, WORLD"), which has the unintended effect of replacing the window contents.
It's my understanding from elsewhere that Javascript replaces the entire contents of the window with the return value of a method, so I've also tried javascript:void(document.write("wut")), but the entire window contents are still replaced.
That's because the page is already loaded and it doesn't know where you want to write to. Use document.documentElement.appendChild(document.createTextNode("HAI, WORLD"))
.
I try to understand your "question", but I think you'd want to let it open up in a new window, right?
Then you'd need to use: javascript:window.open("<url to website>", "some title");
If document.write()
is called after the page has finished loading, the entire contents of the page will be overwritten. This is the intended effect of the function.
If you wish to modify the HTML code on the fly, you have a few options:
document.getElementById("foobar").innerHTML("baz")
document.getElementById("foobar").appendChild(document.createTextNode("baz"))
Additionally, you should look into a framework like jQuery, which can handle a lot of this for you:
$("#foobar").html("baz")
yeah as Elijah said, or if you want to alter the browser's status bar:
window.status = 'my new status'
精彩评论