aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes document.createTextNode But Need To Render a href Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "document.createTextNode But Need To Render a href" Watch "document.createTextNode But Need To Render a href" New topic
Author

document.createTextNode But Need To Render a href

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6

I have an array of data. Each array element will be data for a TD in a table. I am using the DOM to create my TBODY with all the rows and data. The problem is that the first elements in the array is actually a string of text containing a link. So it looks like

"<a href='fjdkslfjklsd'>view</a>"

The problem is that using document.createTextNode and passing in that value it is just displaying plain text. The next problem is that simply using document.createElement("A") and creating the link that way won't work because I can't always be sure that the link will appear as the first element in the array as I am not the only one using this function. Does anyone know what I might be able to do to solve my issues?

Thanks.


GenRocket - A Test Data Generation Platform
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

If you've already got pre-formatted HTML, use innerHTML rather than DOM manipulation.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6

Originally posted by Bear Bibeault:
If you've already got pre-formatted HTML, use innerHTML rather than DOM manipulation.


Well, that's the problem. For some reason I am having issues with IE an innerHTML when I try and add text to the tbody of a table. I can some obscure "runtime error". Firefox works great. So I switched to this method to see if I could solve the problem this way, and then of course ran into other problems.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
not sure if this even works, never tried it, but popped into my head.

will a try catch stament catch IE's problem with innerHTML? If so maybe this would work, (Have no clue)



or maybe object detection



Wish I had a real solution other then saying, redeisgn the strings to use createElements!!

Eric
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
OH MAN!!!

My last sentence turned on a lightbulb.....

IE does allow this, FF/Moz does not

var eHTML = document.createElement("<a href='blah'>asdf</a>");

so you may be able to do this if you can catch that error like I mentioned above.

Eric
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6

Thanks for the suggestions. But I guess what I really want to know is why can't IE do this...





Firefox does it. But IE gives that 'unknown runtime error'.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

Originally posted by Gregg Bolinger:
what I really want to know is why can't IE do this...


Do you really need the obvious answer?
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6

Originally posted by Bear Bibeault:


Do you really need the obvious answer?




Well, after much trial and error I finally got something to work. I had to use insertRow and insertCell so I had to completely change my function. Better or worse? Who cares, it works. I am tired of javascript!!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: document.createTextNode But Need To Render a href
 
Similar Threads
problem with xml parsing
xml problem
&nbsp; in text Node
Generating XML from java
DCD validating parser