Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-20-2006, 10:07 AM   PM User | #1
imaginarydivabc
New to the CF scene

 
Join Date: Jul 2006
Location: British Columbia Canada
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
imaginarydivabc is an unknown quantity at this point
Convert Javascript to html

Is there such a thing? I am trying to convert a javascript code into html based so that my blogger post can take it. There are a lot of html to javascript but not the other way around. Hope someone can help. I would really appreciate it.
imaginarydivabc is offline   Reply With Quote
Old 10-20-2006, 04:06 PM   PM User | #2
mic2100
Regular Coder

 
mic2100's Avatar
 
Join Date: Feb 2006
Location: Scunthorpe
Posts: 562
Thanks: 15
Thanked 28 Times in 27 Posts
mic2100 is on a distinguished road
it depends wot u r trying to convert perhaps you could show your code and explain wot u r wanting to do with each bit of it.
mic2100 is offline   Reply With Quote
Old 11-05-2006, 04:34 AM   PM User | #3
imaginarydivabc
New to the CF scene

 
Join Date: Jul 2006
Location: British Columbia Canada
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
imaginarydivabc is an unknown quantity at this point
Javascript to html

I get a code <script> </script> and I need to convert that into an <a href> or <iframe>. I am hoping you would be able to help me with this.
imaginarydivabc is offline   Reply With Quote
Old 11-05-2006, 04:59 AM   PM User | #4
VortexCortex
Regular Coder

 
Join Date: May 2005
Posts: 142
Thanks: 0
Thanked 0 Times in 0 Posts
VortexCortex is an unknown quantity at this point
Cool You need to replace the <, > and &...

To show your JavaScript and/or HTML source code:

Save this as js2html.html
PHP Code:
<html>
<
head><title>JavaScript to HTML</title>
<
script type="text/javascript">
function 
encode(){
    var 
document.getElementById('source');
    var 
txt s.value;
    
txt txt.replace(/[&]/g,'&amp;');
    
txt txt.replace(/[<]/g,'&lt;');
    
txt txt.replace(/[>]/g,'&gt;');
    
s.value txt;
}
</script>
</head>
<body>
<button onclick="encode()">Convert to HTML</button><br />
<textarea id="source" style="width:90%;height:400px"></textarea>
</body></html> 
Open js2html.html with your web browser.
Paste in the HTML and/or Javascript code you wish to convert.
Click the convert button ONLY ONCE.
copy and paste the result into the blog.

You may desire to place the output between <pre> and </pre> tags in order to preserve the formatting of the code.

If your aim is to get the script to run on your blog, and you're getting <script> tags then you are not allowed to post JavaScript to your blog. The blog is doing exactly what the code above does... Get a better blog.

Last edited by VortexCortex; 11-05-2006 at 05:12 AM.. Reason: added instructions
VortexCortex is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
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 +1. The time now is 08:36 PM.


Advertisement
Log in to turn off these ads.