javascript - How to change an image link based on content in another page -


i want put image on page (page1) link page (page2), want image displayed 1 of 2 possible images, based on content of page2.

page2 in case wiki page reports current status. if there no problems report, image on page1 green in color. if there problems listed, image red.

my plan accomplishing use html comment tags embed either <!--statusred--> or <!--statusgreen--> on wiki page. figured use javascript, jquery or similar check presence of comment , alter image on page1 accordingly. not sure how this.

i open other ideas. whatever solution come with, has simple wiki user change without requiring user change page1 (which not part of wiki).

update:

what ended doing:

$(document).ready(function() {     statuscheck();     setinterval(statuscheck,300000); }  function statuscheck() {     $.ajax({         type: "get",         url: "path/to/wiki/mainpage.ashx",         datatype: "html",         cache: false,         success: function(html) {             $('#statusimage').attr('src', function() {                 if ($(html).find("#statusgreen").length)                 {                     return '/images/green.gif';                 }                 else                 {                     return '/images/red.gif';                 }             });                  },         error: function(request,status, error) {             $('#statusimage').attr('src', '/images/red.gif');         }            }); } 

and on wiki page change id attribute on div in question either 'statusgreen' or 'statusred' so:

<div id="statusgreen"> <font size="5" color="green">no issues report.</font> </div> 

and image want change gets 'statusimage' id:

<img id="statusimage" width="95" height="95" border="0" /> 

this wasteful wiki page's content check presence of single word, anyway, here's how it:

<div id="hidden_container" style="display: none;"></div> <img src="" id="wikistatus"/>  function set_status() {   var status_image = 'images/green.gif';   $('#hidden_container').empty();   $('#hidden_container').load('path/to/wiki.html #status', function() {     var status = $('#hidden_container').text();     var is_green = status.indexof('<!--statusgreen-->');     if(is_green === false) status_image = 'images/red.gif';     $('#wikistatus').attr('src', status_image);     settimeout('set_status();', 5000); // execute again in 5 seconds   }); }  $(document).ready(function() {   set_status(); }); 

in wiki.html make sure wrap status code in container status id:

<div id="status"><!--statusgreen--></div> 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -