Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Jan 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question : change javascript into HTML ?

    Hello ,

    I have a javascript and I need to transform it into a HTML.
    The javascript is :

    <script type="text/javascript" src="http://ad.adsonpop.com/4887/6.js"></script>

    I ask to someone ,for solve this for me .

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,350
    Thanks
    13
    Thanked 349 Times in 345 Posts
    not possible. JavaScript is a programming language and HTML a markup language. that would be like transforming a dog into a tree.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #3
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    The script tag is HTML and is the appropriate HTML to attach the JavaScript. There is nothing to convert.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #4
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,316
    Thanks
    29
    Thanked 280 Times in 274 Posts
    Quote Originally Posted by dacrib View Post
    I have a javascript and I need to transform it into a HTML.
    The javascript is :

    <script type="text/javascript" src="http://ad.adsonpop.com/4887/6.js"></script>

    I ask to someone ,for solve this for me .
    Easy enough:

    Code:
    <![CDATA[<script type="text/javascript" src="http://ad.adsonpop.com/4887/6.js"></script>]]>
    For every complex problem, there is an answer that is clear, simple, and wrong.

  • #5
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Quote Originally Posted by Arbitrator View Post
    Easy enough:

    Code:
    <![CDATA[<script type="text/javascript" src="http://ad.adsonpop.com/4887/6.js"></script>]]>
    Isn't that converting it FROM HTML to data rather than TO HTML?
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #6
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,316
    Thanks
    29
    Thanked 280 Times in 274 Posts
    Quote Originally Posted by felgall View Post
    Isn't that converting it FROM HTML to data rather than TO HTML?
    Ever a stickler for semantics, eh, felgall? Oh, fine...

    Code:
    <code><![CDATA[<script type="text/javascript" src="http://ad.adsonpop.com/4887/6.js"></script>]]></code>
    Fixed.

    Some other tacks:

    Media Type: application/xhtml+xml (XHTML is now folded into HTML!)
    Code:
    <script><!--
    	"use strict";
    	var script = document.createElement("script");
    	script.setAttribute("src", "http://ad.adsonpop.com/4887/6.js");
    	document.body.appendChild(script);
    --></script>
    I also tried addType text/html .js and addType application/xhtml+xml .js to no effect. Firefox renders standalone *.js files as HTML, but ignores the media type when referenced via script elements. Oh well, can't win 'em all.
    For every complex problem, there is an answer that is clear, simple, and wrong.

  • #7
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,350
    Thanks
    13
    Thanked 349 Times in 345 Posts
    MIME headers override client-side type definitions.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #8
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Quote Originally Posted by Arbitrator View Post
    Some other tacks:

    Media Type: application/xhtml+xml (XHTML is now folded into HTML!)
    Code:
    <script><!--
    	"use strict";
    	var script = document.createElement("script");
    	script.setAttribute("src", "http://ad.adsonpop.com/4887/6.js");
    	document.body.appendChild(script);
    --></script>
    The following ought to treat the content of the JavaScript file as XHTML without needing to update the MIME type on the server end:

    <script type="application/xhtml+xml" src="http://ad.adsonpop.com/4887/6.js"></script>
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #9
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,316
    Thanks
    29
    Thanked 280 Times in 274 Posts
    Quote Originally Posted by Dormilich View Post
    MIME headers override client-side type definitions.
    Not exactly, as I indicated in my previous post. As long as a JavaScript MIME type is specified in a script element's type attribute (or defaults to text/javascript when the attribute isn't specified), the browser will execute the script regardless of what the content-type HTTP header says. This seems to be the case for Chrome 32, Firefox 26, and IE11.

    As far as I can tell, this is an HTML spec violation per http://www.whatwg.org/specs/web-apps...ptingLanguages and "[u]ser agents may support other MIME types for other languages, but must not support other MIME types for the languages in the list above" where "above" refers to JavaScript MIME types.

    Quote Originally Posted by felgall View Post
    The following ought to treat the content of the JavaScript file as XHTML without needing to update the MIME type on the server end:

    <script type="application/xhtml+xml" src="http://ad.adsonpop.com/4887/6.js"></script>
    Yeah, that mostly works. I didn't even think to try it after misreading the HTML spec.

    Chrome 32 and Firefox 26 don't download the file, so they don't have an opportunity to ignore the media type.

    I say "mostly works" because IE11 downloads and executes the script regardless of what the type attribute or content-type header says unless the type attribute lists one of the four media types at the end of http://www.whatwg.org/specs/web-apps...ptingLanguages. (The closest one for the purposes of this thread is application/xml lol.) In the latter case, the script is still downloaded, it just isn't used.
    For every complex problem, there is an answer that is clear, simple, and wrong.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •