Java Script navigation not working?
I want to make a navigation bar in JavaScript on my website so I only have to edit one file when I want to add a new page to my website. After looking up tutorials I found one that does almost what I want however even this one doesn't work.
function nav(String url)
{
window.location.href = url;
}
<form>
<input type="button" value="开发者_JS百科Home" onclick="nav(http://www.atsbusinessandgames.co.cc/)" />
</form>
However this won't show up in my navigation bar. Also I want it to look like any other link and not be a button if possible. Any help is greatly appreciated.
You're thinking Java, you don't specify the type in function parameters in JS.
function nav (url) {
window.location.href = url;
// or window.location = url;
// sometimes window.location.href = ...
// behaves in a funny manner cross-domain.
}
<form>
<input type="button" value="Home" onclick="nav('http://www.atsbusinessandgames.co.cc/');" />
</form>
Oh, and, apologies, should also note the single-quotes around the url.
精彩评论