• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

How to make javascript run *sometimes* when a page loads

Bulldog13

Golden Member
Basically,

I have a webpage that uses the following function :

var setInnerHTML = function( id, str ){
if(!document.getElementById) return; // Not Supported
if(document.getElementById){
document.getElementById(id).innerHTML = str;
}

When the user clicks on a certain link on the page, the page is dynamically changed. It allows me to keep all information on a certain topic on a single .html file.

Here is an example of the actual function call.

onclick="setInnerHTML('contentalt1',foo);"

It works great. I can click on a link and change whatever I want inside of a given html page. Thought I was being clever, shrinking the number of html files.

The problem now is how do I link to abc.html and run setInnerHTML('contentalt1',foo2) as soon as the page loads (essentially changing the default text for abc.html)? Obviously, I could just drop it in the <body> tag, but then that would break it everywhere else because I don t want that text displayed first, except when the certain link on a different page is clicked.

Thoughts ?



 
If you've got some kind of server side language, take a parameter that specifies which chunk of content to show. Then, when rendering the page, put the correct content in dynamically (or put in the correct javascript call on the body.onload).
 
Back
Top