Results 1 to 2 of 2

Thread: Always on Top Message Not Woking in IE

  1. #1
    Join Date
    Oct 2007
    Posts
    32
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Always on Top Message Not Woking in IE

    1) Script Title: Always on Top Message

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex10/topmsg.htm

    3) Describe problem: I have used this script successfully on a site I am running. I am designing a new site, and at this point, I am running a testing server on my local machine, so there is no live link for you to look at. Basically, I am using a bit of PHP code to parse the URL of of the page, and if the condition is met, that is, the directory "census" is found in the URL, then the script is dynamically added and run at the very end of the page, just before the body tag, as it should be. All is fine in Firefox, Opera, Safari, and Google Chrome. In IE7 which is the only IE on my machine, I get the following error message:
    Line: 74
    Char:1
    Error: topmsg_obj.style is not an object.
    Code: 0

    Here is the snippet of code that checks for the condition:

    Code:
    <?php
    $pageURL = 'http';
     if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
     $pageURL .= "://";
     if ($_SERVER["SERVER_PORT"] != "80") {
      $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
     } else {
      $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
     }
    $parsedURL = parse_url ($pageURL);
    
    $splitPath = explode ('/', $parsedURL['path']);
    
    if (in_array("census",$splitPath))
      {
      echo "<script type=\"text/javascript\" src=\"/scripts/topmsg.js\"></script>\n";
    
      }
    else
      {
      return;
      }
    
    
    ?>
    </body>
    </html>

    Here is the code for the topmsg.js script that I have modified for my use:
    Code:
    //Always-on-top message Script- © Dynamic Drive (www.dynamicdrive.com)
    //For full source code, and Terms Of use, visit dynamicdrive.com
    //This credit MUST stay intact for use
    //enter the message you wish to be shown, including html tags
    var message='<nobr><div style="z-index:10000; position:relative;" class="whiteback greencorners"><a href="javascript:printTranscription();" onclick="window.open(countries.tabs[countries.currentTabIndex].rel + \'.html?tngprint=1\', \'_blank\', \'width=800, height=600\'); return false;" title="Click Here To Print This Census Transcription"><img src="/images/printericon.jpg" width="30" alt="Click Here To Print This Census Transcription"/><span style="font-size:24px;">Click Here To Print This Census Transcription</span><img src="/images/printericon.jpg" width="30" alt="Click Here To Print This Census Transcription"/></a></div></nobr>';
    
    //enter a color name or hex to be used as the background color of the message
    var backgroundcolor="#FFFF8A"
    
    //enter 1 for always display, 2 for ONCE per browser session
    var displaymode=1
    
    //Set duration message should appear on screen, in seconds (10000=10 sec, 0=perpetual)
    var displayduration=0
    
    //enter 0 for non-flashing message, 1 for flashing
    var flashmode=1
    //if above is set to flashing, enter the flash-to color below
    var flashtocolor="lightyellow"
    
    
    ///////////////do not edit below this line////////////////////////////////////////
    var ie=document.all
    var ieNOTopera=document.all&&navigator.userAgent.indexOf("Opera")==-1
    
    function regenerate(){
    window.location.reload()
    }
    
    function regenerate2(){
    if (document.layers)
    setTimeout("window.onresize=regenerate",400)
    }
    
    var which=0
    
    function flash(){
    if (which==0){
    if (document.layers)
    topmsg_obj.bgColor=flashtocolor
    else
    topmsg_obj.style.backgroundColor=flashtocolor
    which=1
    }
    else{
    if (document.layers)
    topmsg_obj.bgColor=backgroundcolor
    else
    topmsg_obj.style.backgroundColor=backgroundcolor
    which=0
    }
    }
    
    if (ie||document.getElementById)
    document.write('<div id="topmsg" style="position:absolute;visibility:hidden">'+message+'</div>')
    
    var topmsg_obj=ie? document.all.topmsg : document.getElementById? document.getElementById("topmsg") : document.topmsg
    
    function positionit(){
    var dsocleft=ie? document.body.scrollLeft : pageXOffset
    var dsoctop=ie? document.body.scrollTop : pageYOffset
    var window_width=ieNOTopera? document.body.clientWidth : window.innerWidth-20
    var window_height=ieNOTopera? document.body.clientHeight : window.innerHeight
    
    if (ie||document.getElementById){
    topmsg_obj.style.left=parseInt(dsocleft)+window_width/2-topmsg_obj.offsetWidth/2
    topmsg_obj.style.top=parseInt(dsoctop)+parseInt(window_height)-topmsg_obj.offsetHeight-4
    }
    else if (document.layers){
    topmsg_obj.left=dsocleft+window_width/2-topmsg_obj.document.width/2
    topmsg_obj.top=dsoctop+window_height-topmsg_obj.document.height-5
    }
    }
    
    function setmessage(){
    if (displaymode==2&&(!display_msg_or_not()))
    return
    if (document.layers){
    topmsg_obj=new Layer(window.innerWidth)
    topmsg_obj.bgColor=backgroundcolor
    regenerate2()
    topmsg_obj.document.write(message)
    topmsg_obj.document.close()
    positionit()
    topmsg_obj.visibility="show"
    if (displayduration!=0)
    setTimeout("topmsg_obj.visibility='hide'",displayduration)
    }
    else{
    positionit()
    topmsg_obj.style.backgroundColor=backgroundcolor
    topmsg_obj.style.visibility="visible"
    if (displayduration!=0)
    setTimeout("topmsg_obj.style.visibility='hidden'",displayduration)
    }
    setInterval("positionit()",100)
    if (flashmode==1)
    setInterval("flash()",1000)
    }
    
    function get_cookie(Name) {
    var search = Name + "="
    var returnvalue = ""
    if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    if (offset != -1) {
    offset += search.length
    end = document.cookie.indexOf(";", offset)
    if (end == -1)
    end = document.cookie.length;
    returnvalue=unescape(document.cookie.substring(offset, end))
    }
    }
    return returnvalue;
    }
    
    function display_msg_or_not(){
    if (get_cookie("displaymsg")==""){
    document.cookie="displaymsg=yes"
    return true
    }
    else
    return false
    }
    
    if (document.layers||ie||document.getElementById)
    window.onload=setmessage
    Any ideas would be greatly appreciated.
    Dwayne

  2. #2
    Join Date
    Oct 2007
    Posts
    32
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Thanks anyway, I solved the problem. I had the 1st snippet of code in two different files, and it was echoing the script to both the top of the page (at the very start of the page, before the Doc type declaration, and also at the bottom of the page where it should be. It was just a silly oversight on my part. The funny thing is Firefox, Opera, Google and Safari didn't care about my mistake, just IE...

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •