Hi,

How can I make a message appear on my website if it's on a specif page of it? I din't write the source. It's HTML. Can I do an If or If While statement making the message appear only if the URL indicates the specific page of the website? You see, the person who did the site did not write comments on it and I'm not a super expert. The images on the site change, but all within a same frame. I will appreciate any help you can give me.

Thanks,

Lex

Recommended Answers

All 2 Replies

this can be done by javascript. you are going to create a div and put your message in it. then you are going to check the url of the webpage and change the display property of the div.style.

Here's a basic sample that you can start with:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<meta http-equiv="Window-target" content="_top">
<title>Free Live Help!</title>
<style type="text/css">
<!--
.normal { color : #909090; }
.dynamic { color : #000; }
-->
/* ]]> */
</style> 
<script id="javascriptv15" type="text/javascript">
<!--
/*******************************
   - Provide all the URLs/Pages that 
   you need inside this 
   array collection.

   - This URLs/Pages will verify 
   true/false coditions inside -
   your (if/else) blocks'.
*******************************/

var $location = [ [ "http://www.somesite.com/", "test.html" ], 

[ '<font color="blue">Message if <font color="red" size="1"><b>http://www.somesite.com/</b></font> is loaded</font>' , 

'<font color="blue">Message if <font color="red" size="1"><b>test</b></font><b>.</b>html is loaded</font>' ] ];


var message = function() {
   var myMsg = (( document.getElementById ) ? document.getElementById("msg") : document.all[ "msg" ] );
   for ( var i = 0; i < $location[ 0 ].length; i++ ) {
      if ((( document.URL.indexOf( $location[ 0 ][ i ] )) || location.href.indexOf( $location[ 0 ][ i ] )) !== -1 ) {
      myMsg.className = "dynamic";
      myMsg.innerHTML = "This is the current location :<br>" + $location[ 1 ][ i ];
      return false;
      }
   } alert( "\n- File not found! -\nPlease make sure that your (x)HTML documents are properly defined inside the $location[ARRAY-OF-PAGES-COLLECTION]" );
}
window.onload = message;

// -->
</script>
</head>
<body>
<div id="main">
<span class="normal" id="msg">Normal Text Content</span>
</div>
</body>
</html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.