CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Installing SQL Server 2008
  • Writing UDFs for Firebird Embedded SQL Server
  • [Updated] Shutdown Manager
  • Building Windows Azure Cloud Service Applications with Azure Storage and the Azure SDK

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Other Programming > Scripting - Client Side
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    Scripting - Client Side Discuss client-side scripting issues. Client-side scripting such as JavaScript, JScript, and VBScript as well as technologies such as HTML and stylesheets.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old October 27th, 2009, 05:24 PM
    Norm Norm is offline
    Elite Member
     
    Join Date: Jun 1999
    Location: Summering in SW MO
    Posts: 2,664
    Norm is on a distinguished road (20+)
    Displaying text over image in IE

    Hi,
    I'm trying to create an HTML page that displays an image and will display a small text at the location the mouse is clicked. I've gotten it to work with Firefox but am unable to get it to work with IE.

    After I determine the text I want to display (its in NamesList[]) at the clicked location I use the following Javascript code:
    Code:
       	  var aDiv = document.createElement('div');
            aDiv.setAttribute("id", LayerNm + divCnt++);
            // Display the name at the upper left of rectangle given in NamesList[]
            var absPt = relToAbs(NamesList[ix+dX], NamesList[ix+dY]);  // get absolute point location
            aDiv.setAttribute("style", 'position:absolute;left:' + absPt.x + 'px;top:' 
                                        + absPt.y + 'px;font-weight:bold;color:cyan');
            aDiv.appendChild(document.createTextNode(NamesList[ix+dName]));	
       	  aDiv.onmousedown = myMouseDown;  // set for new div
       
            imgDiv.parentNode.insertBefore(aDiv, imgDiv);  // works!!!
    Definitions from other parts of code:

    Code:
             imgDiv = document.getElementById('Image');  // set global one time here
       ...
    <CENTER><IMG SRC="1990_Reunion-300_ED1.jpg" HEIGHT="96%" ALT="1990 Reunion" id="Image"></CENTER>
       ...
    Works in Firefox, but not in IE.
    Is there code that will work in both browsers?
    Is there code that will work in IE that I can use if in IE?

    Thanks,
    Norm
    __________________
    Norm

    Last edited by Norm; October 27th, 2009 at 05:27 PM.
    Reply With Quote
      #2    
    Old November 3rd, 2009, 11:00 AM
    Xeel's Avatar
    Xeel Xeel is offline
    Member
     
    Join Date: Jul 2005
    Location: Currently in Mexico City
    Posts: 430
    Xeel has a spectacular aura about (125+)Xeel has a spectacular aura about (125+)
    Re: Displaying text over image in IE

    If you understand what you are doing:

    To make a child element's absolute position be relative to a parent element you have to declare this parent's style as "position:relative". Otherwise the child element will take a lower level parent with this property declared, down to the document window itself if no parent has it's position set "relative".

    Also I would strongly recommend playing with position style property for DIV elements only, other elements have problems with it.

    So instead of calculating absolute paths from the document widow or anywhere else you could:

    1. Enclose image in a div (later "parent div") with position property set to relative.
    2. Inside the parent div somewhere after the image tag enclose in a div the element you want to be over the image setting its position to absolute and its left and top properties to some fixed values which will be the same for all images if there is more.
    __________________
    Wanna install linux on a vacuum cleaner. Could anyone tell me which distro sucks better?

    willCodeForFood("PHP,Java,C#,C++,Assembler,XML,VBS,XHTML,CSS,JavaScript,SQL"); //always looking for job opportunities in AU/NZ/US/CA/Europe :P
    USE [code] TAGS! Read this FAQ if you are new here. If this post was helpful, please rate it!

    Last edited by Xeel; November 3rd, 2009 at 11:07 AM.
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > Other Programming > Scripting - Client Side


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 01:00 AM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
    Copyright WebMediaBrands Inc. 2002-2009