|
|
|
|
![]() ![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 372 Joined: 16-August 04 From: Spain Member No.: 824 |
Post
#1
May 18 2005, 08:01 AM
Hi, I have the next html page CODE <html> <head> <script> <!-- function insertcode() { var code ="<p> blablabal babala babababab</p><h1>here comes header</h1><span>fadfafa<a href=\"fadfaf\">anchor</a>blalbababa</span>" var myText = document.createTextNode(code); document.getElementById("content").appendChild(myText); } --> </script> </head> <body> <div id="content"> </div> <a href="javascript:insertcode()">Insert Code</a> </body> </html> This code insert the data as text. The html tags are not treated like markup. I need to insert the code in a time. I mean i can not go tag per tag. (E.g. document.createElement("p")... ) Is there any method to insert a pice of html code into a div and keep it like code not like text in Javascript? I hope you understand my problem. If not please tell me. Thanks in advanced for your help. |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Admin
Posts: 3,763 Joined: 23-April 05 From: Trap17 storage box Member No.: 6,042 myCENT:48.70 |
Post
#2
May 18 2005, 08:30 AM
I couldn't understand what you were trying to do. I think you are trying to place another HTML/text page in your HTML page. I saw this code somewhere in this forum but I cannot find who wrote it at this time. A apologize to the author for posting without crediting you. I will come back and correct it once I find it. (or someone PM me if you find it) HTML <object type="text/x-scriptlet" width=100% height="250" data="Your Html File(TextFile )"> </object> This simple liner, I was told, that allows you to place another html/text page into your html page. It's a document within the document. I'm telling ya, we got some brilliant codeboys here! |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 1,161 Joined: 9-May 05 From: Brisbane, QLD Member No.: 6,818 |
Post
#3
May 18 2005, 08:40 AM
QUOTE(mizako @ May 18 2005, 06:01 PM) Is there any method to insert a pice of html code into a div and keep it like code not like text in Javascript? Why is it necessary to insert it as HTML instead of javascript? It should still validate OK. And why are you using javascript to insert the code in the first place? Why not just type it out? |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 372 Joined: 16-August 04 From: Spain Member No.: 824 |
Post
#4
May 18 2005, 06:32 PM
QUOTE(Tyssen @ May 18 2005, 08:40 AM) Why is it necessary to insert it as HTML instead of javascript? It should still validate OK. And why are you using javascript to insert the code in the first place? Why not just type it out? [right][snapback]142540[/snapback][/right] Ok, i will try to explain myself better. Basically i am working on a Remote Scripting using hidden frames (i will explain what it is this in another topic). project. I have a database in MySQL where in one table i have a biography in XHTML. I access this table with PHP and i retrive this XHTML code. Then the Javascript function obtains the code and has to insert it into a this "div" element. As i explain in my first post. ;-) I know the mechanismus is complicated but i have to do it in this way. I hope you both understand better what i am asking for. I did not understand your solution BuffaloHELP but thanks both of you for your answers. Does anyone knows one can i solve this Javascript Issue? |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 1,161 Joined: 9-May 05 From: Brisbane, QLD Member No.: 6,818 |
Post
#5
May 18 2005, 10:23 PM
QUOTE(mizako @ May 19 2005, 04:32 AM) Ok, i will try to explain myself better. Basically i am working on a Remote Scripting using hidden frames (i will explain what it is this in another topic). project. I have a database in MySQL where in one table i have a biography in XHTML. I access this table with PHP and i retrive this XHTML code. Then the Javascript function obtains the code and has to insert it into a this "div" element. You don't need javascript to write out the code, you can use PHP. You're using just about the same language anyway and you're already using PHP to retrieve the info from the database. It seems logical that you would then use PHP to just print it out using echo or print. You could use PHP code to print your whole page if you wanted to: CODE <?php print "<head>"; print "<title>Your title</title>"; print "<body>"; etc. |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 372 Joined: 16-August 04 From: Spain Member No.: 824 |
Post
#6
May 19 2005, 12:45 PM
QUOTE(Tyssen @ May 18 2005, 10:23 PM) You don't need javascript to write out the code, you can use PHP. You're using just about the same language anyway and you're already using PHP to retrieve the info from the database. It seems logical that you would then use PHP to just print it out using echo or print. You could use PHP code to print your whole page if you wanted to: As i wrote in my second message i am trying to implement Remote Scripting which aims to reduce the code (avoiding redundant markup) sent by the server to the client. That it is to say that the PHP scripts just send plain text to the client and the client creates the interface by means of Javascript. I know PHP and i know that i can write the whole page with PHP but i need to do it by Javascript. I did not want to begging a topic about Remote Scripting in this thread (maybe in another one), i just wanted to obtain a Javascript solution for the problem i exposed. I appreciate a lot your help but please answer me with a Javascript solution if you know it. Thanks in advanced! |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 372 Joined: 16-August 04 From: Spain Member No.: 824 |
Post
#7
May 23 2005, 07:22 PM
Hello, I found the solution :-) . Somebody point me to the "innerHTML" method. The Code with the included solution is the next: HTML <html> [note=BuffaloHELP]Entered [html] tags.[/note]
<head> <script> <!-- function insertcode() { var code ="<p> blablabal babala babababab</p>"; code += "<h1>here comes header</h1>"; code += "<span>fadfafa<a href=\"fadfaf\">anchor</a>blalbababa</span>"; document.getElementById("content").innerHTML = code; } --> </script> </head> <body> <div id="content"> </div> <a href="javascript:insertcode()">Insert Code</a> </body> </html> This post has been edited by BuffaloHELP: May 23 2005, 08:20 PM |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 283 Joined: 10-October 04 Member No.: 1,637 |
Post
#8
May 23 2005, 08:00 PM
oh you got it.. i read ur topic and just floating with javascript site to find about this!! i swear.. anyway, hey u forgot to put code tag on last post as you r hurry right!!! |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 5,876 Joined: 21-September 07 Member No.: 50,369 |
Post
#9
Apr 27 2009, 08:42 AM
dynamic script tag How To Insert Code With Javascript I need to insert a script tag dynamically which calls google search api...The problm is that I cant find a way to insert the source of the script tag that call thaat search api :S can anyone help pls? -reply by mmmrt
|
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 5,876 Joined: 21-September 07 Member No.: 50,369 |
Post
#10
Apr 30 2009, 02:08 PM
use the innerHTML property to insert markup. This is an IE invention but is supported in Firefox and Opera as well. It's not pretty, and if you're inserting something fixed you should probably create the markup properly (using createElement, createTextNode etc...), but when you're inserting someone elses text/markup it seems to work! -reply by sabroni
|
![]() ![]() |
Similar Topics
| Topic Title | Replies | Topic Starter | Views | Last Action | |||
|---|---|---|---|---|---|---|---|
![]() |
3 | -Sky- | 664 | 12th June 2009 - 08:48 PM Last post by: -Sky- |
|||
![]() |
7 | odomike | 19,029 | 30th April 2008 - 02:44 PM Last post by: FeedBacker |
|||
![]() |
97 | Xenon | 47,384 | 29th October 2009 - 04:25 PM Last post by: magiccode9 |
|||
![]() |
10 | Vacant | 5,461 | 3rd June 2009 - 05:11 PM Last post by: proskiier23 |
|||
![]() |
11 | bttfpromo | 11,547 | 14th September 2004 - 08:55 PM Last post by: Magic-Node |
|||
![]() |
10 | holyium | 9,968 | 25th September 2004 - 12:33 AM Last post by: spyshow |
|||
![]() |
3 | Vacant | 7,857 | 26th August 2004 - 09:09 AM Last post by: Vacant |
|||
![]() |
6 | XtremeGamer99 | 6,316 | 9th February 2005 - 10:48 AM Last post by: alexwhin |
|||
![]() |
25 | gijoe18 | 24,501 | 20th February 2009 - 06:55 PM Last post by: MALISH_ |
|||
![]() |
1 | BCD | 180 | 3rd September 2009 - 09:28 PM Last post by: truefusion |
|||
![]() |
5 | Tetraca | 1,252 | 15th July 2006 - 11:06 PM Last post by: Plenoptic |
|||
![]() |
4 | icss21 | 3,027 | 7th March 2009 - 09:45 PM Last post by: andreip |
|||
![]() |
3 | jglw22 | 891 | 26th May 2008 - 02:10 PM Last post by: Framp |
|||
![]() |
4 | Forbidden | 7,570 | 28th March 2008 - 07:37 PM Last post by: saran |
|||
![]() |
6 | sargilla | 6,812 | 4th November 2004 - 02:54 PM Last post by: Lyon |
|||
|
Open Discussion | Time is now: 22nd November 2009 - 09:36 AM |
Web Hosting Powered by ComputingHost.com.