JavaScript

Apprentice
Posts: 9
Joined: 2007.07
Post: #1
I've got this book on JavaScript(Wrox beginning JavaScript) it's good but...
I cant run my code, on the instructions (for windows) i edit in the text editor and open with Internet explorer, I tried that in mac and it doesnt work Annoyed

Does anyone know how to run my JavaScript/HTML code on a mac??

----------------------------------------------------
Solution:
What you need to do, is while in textedit, go to the "Format" menu and choose "Make plain text", save it with the extension .html and open! ^^

thank u for all that helped!
Quote this message in a reply
Moderator
Posts: 623
Joined: 2007.09
Post: #2
What text editor are you using on the Mac?
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #3
First thing that comes to mind is that the line endings are incorrect. Another thing that comes to mind is that I wouldn't bother with Internet Explorer for anything since it sucks so bad -- especially on Windows, but also on the Mac. The last thing that comes to mind is, are you sure your Javascript is correct?
Quote this message in a reply
Moderator
Posts: 623
Joined: 2007.09
Post: #4
Or maybe he accidentally saved it as richtext…
Quote this message in a reply
Apprentice
Posts: 9
Joined: 2007.07
Post: #5
I use the TextEdit application.

And by what i see on windows the internet explorer(which i also agree that it sucks) when opens a file with HTML, it reads the code and interprets it(including the JavaScript in the code), but it doesn't do that if in the options menu it's marked not to do, in that case it just opens the text file with the code on it(this is what happens in the mac too, with firefox and safari).

the problem isnt with the code or the format.

I just need to activate something to interpret the code(HTML/JS) and execute it, or maybe an app that also does that.
Quote this message in a reply
Member
Posts: 715
Joined: 2003.04
Post: #6
Textedit normally saves RTF
And if you are saving as HTML, it thinks what you typed is styled text
that is supposed to show up on the page.

Try changing fonts,sizes and colors and save as html..you'll see what I mean.

Check out Smultron and Editra for your coding text needs.

You'll be good to go.
You should not embed your javascript in the Html by the way.
Save as a .js file and use
Code:
<script src="thescriptname.js" type="text/javascript">
//or
<script language="JavaScript" src="yourfile.js"></script>

in the body of your HTML code.




You should be able to test your .js files and scripts in the browser address bar.
Ex:
jalert("It works!")
file:///path/to/your/javascript.js
file:///path/to/your/webpage.html
Quote this message in a reply
Moderator
Posts: 623
Joined: 2007.09
Post: #7
What you need to do, is while in textedit, go to the "Format" menu and choose "Make plain text". That way, when you save it, it will be plain text. You can then change the extension to .html and open it with a web browser.
Quote this message in a reply
Apprentice
Posts: 9
Joined: 2007.07
Post: #8
No that isn't the problem (i think). In the preference of the TextEdit it automatically changes the font when save to html. i will keep trying and edit here later


Edit:

Wohooooooo it worked!!!!

I have to convert it to plain text and save it to .HTML and just open it in safari!!!

later i will try i game3d's method, should work too. ohh yes and i did this simple code to test if it works:

Code:
<html>
    <head>
        <title>Work!!!</title>
    </head>
    <body>
        <script language="JavaScript">
            document.write("Work!!");
        </script>
    </body>
</html>
ohh and one more question how do i make that box around my code???
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #9
Glad you got it to work!

Wise Druid Wrote:ohh and one more question how do i make that box around my code???
On the message editing page, select the code you want to be in a code box and click on the # sign on the right, just above the editor. Or you can manually add the tags yourself.
Quote this message in a reply
Apprentice
Posts: 9
Joined: 2007.07
Post: #10
Code:
//Thanks ;p

Yes now it works fine!! just need the TextEdit and safari!
Ohh and you can use JS to make dashboard widgets (using Xcode).

But i don't think there is an IDE for HTML/JS...
Quote this message in a reply
Member
Posts: 715
Joined: 2003.04
Post: #11
Wise Druid Wrote:But i don't think there is an IDE for HTML/JS...

Dreamweaver?

Or maybe OpenMocha?, which is free.
Quote this message in a reply
Moderator
Posts: 623
Joined: 2007.09
Post: #12
Wise Druid Wrote:No that isn't the problem (i think). In the preference of the TextEdit it automatically changes the font when save to html. i will keep trying and edit here later


Edit:

Wohooooooo it worked!!!!

I have to convert it to plain text and save it to .HTML and just open it in safari!!!

later i will try i game3d's method, should work too. ohh yes and i did this simple code to test if it works:

Code:
<html>
    <head>
        <title>Work!!!</title>
    </head>
    <body>
        <script language="JavaScript">
            document.write("Work!!");
        </script>
    </body>
</html>
ohh and one more question how do i make that box around my code???

Glad it worked. I am currently trying TacoHTMLEdit which imho is pretty good. You would probably just want to try out all the suggestions and choose for yourself.
Quote this message in a reply
Member
Posts: 118
Joined: 2002.08
Post: #13
Wise Druid Wrote:But i don't think there is an IDE for HTML/JS...

Checkout Textmate-- or Coda if you want a little more structure. Both work grand for JS and HTML.
Quote this message in a reply
Apprentice
Posts: 9
Joined: 2007.07
Post: #14
I used Taco HTML Edit, And it worked for me!
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Odd javascript bug anthony 2 3,909 Nov 28, 2010 08:29 AM
Last Post: anthony
  JavaScript in Cocoa tutorial willThimbleby 4 4,946 Apr 27, 2006 05:12 PM
Last Post: Skorche
  Help with text-based (Javascript) RPG assylian 3 4,961 Mar 18, 2006 03:18 PM
Last Post: Justin Brimm
  Anyone wants to make a JavaScript file OOP? Taxxodium 1 2,827 Sep 23, 2005 02:28 AM
Last Post: Taxxodium