Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q505 How can I reload the current page and change the background and foreground colors?

irt.org | Knowledge Base | JavaScript | Cookie | Q505 [ previous next ]

Q505 How can I reload the current page and change the background and foreground colors?

Cookies would be one way, another would be to use the locations search property. This is likely to work in more cases then using a cookie, which are sometime rejected by visitors.

Change the location to the current location plus some extra stuff. For example, if the current page is apage.html, and the colors to use are black (#000000) for the text and white (#FFFFFF) for the background then change the page location using:

<html>
<script language="JavaScript"><!--
var output = '<body bgcolor="#000000" text="#FFFFFF">';

if (location.search.length > 0) {
    var input = unescape(location.search.substring(1))
    var bgcolor = input.substring(0,7);
    var text = input.substring(8,15);
    output = '<body bgcolor="' + bgcolor + '" text="' + text + '">';
}

document.write(output);
//--></script>

<form>
<input type="button" value="Change Colors" onClick="location.href = 'color.html?' + escape('#FFFFFF') + '&' + escape('#000000')">
</form>

</body>
</html>

Internet Explorer 4 allows you to dynamically alter the color properties, but the above offers a browser compatiable solution.


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 6th July 2009. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2009 irt.org, All Rights Reserved.