So I have unique project I need to complete... and I have to use JavaScript. Below is the script. There are some vars declared outside of function, and I didn't include that part of the code.
I'm struggling with #4 in the code below. // 4) Test on whether to show a message for a page: First, is there a date condition? If more than one date range, then choose narrowest. Then if there is more than one message, randomize.
Any help would be appreciated.
Code:// Start Pagelogic function pagelogic () { // Set var of element ID that we will be updating... var elemID = document.getElementById("messageBox"); // 1) Are there any CRITICAL messages? If so, test their conditions and possibly show. if (critical_message != "") { var messageShow = critical_message; } // 2) Are we on the search results page? If so, do the search results tests - first for exact matches of the search query, then for the presence of a string in the search query. else if (document.title=="Search Results") { // Test... will be replaced with nested if, else statements. var messageShow = 'This is the Search Results Page'; setCookie("page_counter",1,tlvp_expiredays); } // 3) If not in search page, then look at page URL. If we're in a page that might have a message, do the tests on whether to show it. else if (document.title == 'Page 2 Test') { var messageShow = "This is page 2. This was set as a required message for this page."; setCookie("page_counter",1,tlvp_expiredays); } else if (document.title == 'Page 3 Test') { var messageShow = "This is page 3. This was set as a required message for this page."; setCookie("page_counter",1,tlvp_expiredays); } // 4) Test on whether to show a message for a page: First, is there a date condition? If more than one date range, then choose narrowest. Then is there more than one message, if so use randomizer else if (d>=sD1 && d<=eD1) { var messageShow = "This message falls within the date range of 5/10 - 5/11"; setCookie("page_counter",1,tlvp_expiredays); } else if (d>=sD2 && d<=eD2) { var messageShow = "This message falls within the date range of 5/10 - 5/13"; setCookie("page_counter",1,tlvp_expiredays); } // 5) If no critical messages, then How recently have we shown any message? We need cookie counter for how many pages since last message. If > 5, proceed, else exit and show no message else if (page_count == page_count_max) { var r_messages = new Array(5); r_messages[0] = "Page Count has hit 5! 1st Random Message"; r_messages[1] = "Page Count has hit 5! 2nd Random Message"; r_messages[2] = "Page Count has hit 5! 3rd Random Message"; r_messages[3] = "Page Count has hit 5! 4th Random Message"; r_messages[4] = "Page Count has hit 5! 5th Random Message"; var randno = Math.floor ( Math.random() * r_messages.length ); var messageShow = r_messages[randno]; } else { } if (messageShow != "" && messageShow != null) { elemID.innerHTML = messageShow; elemID.style.display="block"; } // AFTER ANY MESSAGE DISPLAY, RESET COUNTER }


Reply With Quote

Bookmarks