Petty_Crim Posted December 29, 2007 Share Posted December 29, 2007 I know theres probably an easy solution to this but nothing seems to come up on google. Basically I'm using javascript to create a url, which is then assigned to a variable and outputted to the web page. The problem is though its outputting it as a string rather then a proper url. My code text_url='www.google.com'; url="<a href='" + text_url + "'>Click Here</a>"; cell_url = row.insertCell(-1); cell_url.appendChild(document.createTextNode(url); This will output as a string: <a href="www.google.com">Click Here</a> I need it outputted as a url though ie Click Here Link to comment https://forums.phpfreaks.com/topic/83559-solved-html-tags-and-hyperlinks-in-javascript/ Share on other sites More sharing options...
BenInBlack Posted December 29, 2007 Share Posted December 29, 2007 you need to use createElement <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Untitled</title> </head> <body> <script language="JavaScript" type="text/javascript"> <!-- var html_element, body_element, a_element, text_node; // the document element in an XHTML document // is always the html element html_element = document.documentElement; // the body element is the second and last child // of the html element body_element = html_element.lastChild; a_element = document.createElement("a"); a_element.href = 'http:\/\/www.google.com'; //newA.text = 'go to google'; text_node = document.createTextNode("A Link to Google"); a_element.appendChild(text_node); body_element.appendChild(a_element); // --> </script> </body> </html> Link to comment https://forums.phpfreaks.com/topic/83559-solved-html-tags-and-hyperlinks-in-javascript/#findComment-425347 Share on other sites More sharing options...
Petty_Crim Posted December 29, 2007 Author Share Posted December 29, 2007 Thanks BenInBlack I was just about to solve this one myself, I found this on the net but yours seems pretty similar: link = document.createElement ('A'); link.appendChild (document.createTextNode ('Click here')); link.setAttribute ('href', 'google.com'); Link to comment https://forums.phpfreaks.com/topic/83559-solved-html-tags-and-hyperlinks-in-javascript/#findComment-425363 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.