Showing posts with label html. Show all posts
Showing posts with label html. Show all posts

Monday, November 12, 2007

Change text link in Javascript

How to change a link text in Javascript



Let's say you have a link, with the anchor text 'mylink', and you want to change this text using Javascript. For this we will use innerHTML attribute. Here it is:

document.getElementByID( 'mylinkid' ).innerHTML = 'my new link text';

You will probably need this if youn need to show/hide some html elements.


Changing text in a link using Javascript

Tuesday, October 16, 2007

Javascript open centered popup window

How to open a centered pop-up window in Javascript


Here is a Javascript function that allows you to open a centered window, no matter what resolution the visitor uses.

function OpenCenteredWindow( url, width, height )
{
var left = Math.floor( (screen.width - width) / 2);
var top = Math.floor( (screen.height - height) / 2);
var winParms = "top=" + top + ",left=" + left + ",height=" + height + ",width=" + width;
winParms += ",toolbar=no,status=no,scrollbars=yes,menubar=no,resizable=no,location=no,directories=no";
var win = window.open(url, '', winParms);
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
return win;
}

There are three parameters:
  • url - the address you want to open in the new window
  • width - the width of the new popup window
  • height - the height of the new centered window
Also you can set what parameters the new window will have: toolbar, status, scrollbars, menubar, resizable, location, directories.

Tuesday, October 9, 2007

Javascript change element visibility

Want to change an element visibility from javascript. Here is an example.

document.getElementById("your_element_id").style.visibility = "hidden";
document.getElementById("your_element_id").style.visibility = "visible";

As you can see the visibility for an element can be hidden or visible. Make sure you have set an ID for your element.