What is button.js?
button.js is a tiny and simple JavaScript framework I put together for my NeoCities website that makes the <button> tag easier to use. It isn't anything special, nor is it something most people can't make themselves; button.js exists as a convenience thing. I made it because I got sick of writing the same code in the head tags of all my pages, and figured others might find it useful.
How do you use button.js?
- Create a file called 'button.js' somewhere your HTML file can reach it.
- Copy and paste the below into it
- Add something like this to your <head> tag:
<script src="button.js">
<script src="../../button.js">
<script src="../scripts/button.js">
Syntax
- For a regular button:
- Simply set an onclick attribute to the button() function.
<button onclick="button('myawesomewebsite.com/blog');"></button>
- Simply set an onclick attribute to the button() function.
- For an anchor:
- Use the anchor() function. It works exactly the same as button(), except links to an anchor instead of a normal page.
button('test') // Goes to 'test'
anchor('test') // Goes to '#test'
- Use the anchor() function. It works exactly the same as button(), except links to an anchor instead of a normal page.
- For an iframe:
- Use the frame() function. This selects a frame based on it's id, and changes it's src tag.
<button onclick="frame('selector', 'myawesomewebsite.com/gallery');"></button>
<iframe src="" id="selector">
</iframe>
- Use the frame() function. This selects a frame based on it's id, and changes it's src tag.
Source Code
function button(x) {
window.location = x;
}
function anchor(x) {
window.location = '#'+x;
}
function frame(x, y) {
document.getElementById(x).src = y;
}