Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

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

You are here: irt.org | FAQ | JavaScript | Cookie | Q505 [ previous next ]

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.

©2018 Martin Webb