Thanks to anyone who may be able to steer me in the right direction :)
Interesting that this works fine in All Browsers BUT Internet Explorer.
fairly simple goal......
get a "src" img element attribute and display it (by manipulating DOM elements) on the webpage under a graphic...(for a dynamic label) - var mainPic = document.getElementById("placeholder");
-
-
var picSrc = mainPic.getAttribute("src");
-
-
var container = document.getElementById("divContainer");//the container div refference so I can use replaceChild() method to replace the targeted <p> Child Node
-
-
var oldText = document.getElementById("replaceMe");
-
var newPara = document.createElement("p");
-
var lableName = document.createTextNode(picSrc); //this variable doesnt want to transfer in IE, works fine in FF and Safari
-
newPara.appendChild(newName);
-
newPara.setAttribute("id","replaceMe");
-
-
container.replaceChild(newPara,oldText);
again, the goal is satisfied if all I can do is get IE to actually out put a dynamic text variable using the DOM with replaceChild()
Is there a known issue with outputing strings using the DOM in IEx?
thanks to all who lend some brain matter.
10 2647
newPara.appendC hild(newName);
You have no variable newName declared.
opps, thanks for the look...I forgot to include it in the Original post, Again heres the weird thing, It works great in all other browsers, and I have tried to look google over and over. Im not sure where to look for this issue. - var mainPic = document.getElementById("placeholder");
-
-
var picSrc = mainPic.getAttribute("src");
-
-
var container = document.getElementById("divContainer");//the container div refference so I can use replaceChild() method to replace the targeted <p> Child Node
-
-
var oldText = document.getElementById("replaceMe");
-
-
var newPara = document.createElement("p");
-
-
var lableName = document.createTextNode(picSrc); //this variable doesnt want to transfer in IE, works fine in FF and Safari
-
var newName = picSrc;
-
newPara.appendChild(newName);
-
-
newPara.setAttribute("id","replaceMe");
-
-
container.replaceChild(newPara,oldText);
acoder 16,027
Recognized Expert Moderator MVP
What's the value of the src attribute? Is it relative or an absolute path?
here is an example of an image name that the script gets and displays on the page perfectly fine with FF and safari.. - //heres the HTML the image src attrib I want to grab....
-
<img src="Single/VG-001B.jpg" alt="" name="placeholder" width="450" height="350" id="placeholder" />
-
-
//heres the javascript targeting that src attrib......
-
-
var mainPic = document.getElementById("placeholder");
-
//set up the PARENT DIV CONTAINER so the child elements can be manipulated
-
//first check if the current pages has the <div id="divContainer"> node there, otherwise forget this section!
-
if(document.getElementById("divContainer")){
-
var picSrc = mainPic.getAttribute("src");
-
var getFullName = picSrc.split("/");//use the "/" character to mark the split point into an array
-
var getName = getFullName[1].split(".");
-
var finalName = getName[0];
-
var container = document.getElementById("divContainer");
-
var oldText = document.getElementById("replaceMe");
-
var newPara = document.createElement("p");
-
var newName = document.createTextNode(finalName);
-
/*var test = document.createTextElement("this is a test");*/
-
/*var myText = document.getElementById("text");*/
-
newPara.appendChild(newName);
-
newPara.setAttribute("id","replaceMe");
-
container.replaceChild(newPara,oldText);
-
}
-
-
//stop the default a link behavior
-
return false;
-
its an absolute path right?
by the way to see the real world example for my client..... http://www.pet-memorial-markers.com/...owerVases.html
the vase name at the bottom of the graphic is the graphic name extracted from the path
again, try it in FF or Safari, and then.......IE and BLAM, no dynamic src attribute rendering to the page.....
one solution I was thinking of was doing detection script for IE, heres the prototype.....
if ( IE ){
then use non-standard INNER HTML to render to the browser
}else{
use standards like the DOM because standards make life easier for humans that build stuff
}
acoder 16,027
Recognized Expert Moderator MVP
If you alert picSrc, you will see that IE converts it to a full path, while the rest of the browsers leave it as you expect it to be.
If i got it right thats more or less what you need -
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
-
-
<html>
-
<head>
-
<title>Dinamic Label</title>
-
</head>
-
-
<script>
-
-
window.onload = function() {
-
imgs = document.getElementsByTagName("img")
-
images = new Array()
-
-
for (x=0; x<imgs.length; x++) {
-
images[x] = new createDynamicLabel(imgs[x])
-
}
-
}
-
-
function createDynamicLabel(imgReference) {
-
this.image = imgReference
-
-
this.name = this.image.src.substring(this.image.src.lastIndexOf("/")+1,this.image.src.lastIndexOf("."))
-
-
this.lineBreak = document.createElement("br")
-
this.image.parentNode.insertBefore(this.lineBreak,this.image.nextSibling)
-
-
this.label = document.createElement("em")
-
this.label.innerHTML = this.name
-
this.label.style.textTransform = "capitalize"
-
this.label.style.font = "bold 11px verdana"
-
-
this.image.parentNode.insertBefore(this.label,this.lineBreak.nextSibling)
-
}
-
-
</script>
-
-
<body>
-
-
<img src="down.gif">
-
-
<br><br>
-
-
<img src="aceitar.gif">
-
-
<br><br>
-
-
<img src="add.gif">
-
-
<br><br>
-
-
<img src="cancelar.gif">
-
-
</body>
-
</html>
-
-
Good luck!
ps: take care with additional blank spaces in the code like in line 32
acoder 16,027
Recognized Expert Moderator MVP
If i got it right thats more or less what you need
Nice! That should do the trick - the most important thing is the use of lastIndexOf().
thanks everyone, all masters...
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Satish.Talyan |
last post by:
hi,
i want to create a dynamic tree hierarchy in javascript.there are two
parts in tree, group & user.when we click on group then users come
under that's tree category will be opened.problem is that i am not able
to arrange three things simultaneously,group,users & there
functionality simultaneously.dynamic means group & users come from
database and groups & users can be increased in number at any time. i
am sending code for that tree...
|
by: Nathan Sokalski |
last post by:
I add several JavaScript events (onchange, onkeypress, etc.) to Controls
using the Add method of the Attributes collection. However, if the
JavaScript code contains certain characters, such as & or < or several
others, it converts them to html, such as & or < which can sometimes
cause my scripts not to work. How can I prevent ASP.NET from doing this?
Thanks.
--
Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansokalski.com/
|
by: Nathan Sokalski |
last post by:
I add several JavaScript events (onchange, onkeypress, etc.) to Controls
using the Add method of the Attributes collection. However, if the
JavaScript code contains certain characters, such as & or < or several
others, it converts them to html, such as & or < which can sometimes
cause my scripts not to work. How can I prevent ASP.NET from doing this?
Thanks.
--
Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansokalski.com/
|
by: Frinavale |
last post by:
Introduction
I've seen many questions asked about how to disable the browser's back button and in the past I've replied with "it's simply not possible". It's not a good idea to disable the back button anyways, if the user ventures away from your page then they wouldn't have this button at their disposal.
The main reason people ask how to control or disable the back button is because they have a need to control sensitive (and/or) dynamic web...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |