program Javascript on mac

Discussion in 'Web Design and Development' started by chipandegg, May 27, 2008.

  1. chipandegg macrumors regular

    chipandegg

    Joined:
    Oct 3, 2007
    Location:
    London
    #1
    I like to program Javascript and HTML using Notepad on MS XP. For my education course.

    With Javascript I use prompt boxes, if statements etc.

    I tried to do the same on Textedit, saving as a HTML file. Though when I opened the page it opened, none of the prompt boxes appeared. It just showed the actual program code on the net. The program code wasn't run in effect.

    Is there a way around this as I use a Mac 90% of the time and would like to program Javascript on it. Keep swapping between the two is taking up my time.

    Many thanks
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #2
    TextEdit is not the same as Notepad, it's more equivalent to Windows Write. If you (for whatever reason) want to use TextEdit for web development then you need to change its mode to plain text rather than the default rich text.

    Really though I suggest getting a different text editor that is made for web development, and offers many nice features. There are a number of free options. I like TextWrangler. There's also Smultron, Taco HTML, etc. Check out the stickies in this forum for a lot more options. You won't regret switching to one of these.
     
  3. chipandegg thread starter macrumors regular

    chipandegg

    Joined:
    Oct 3, 2007
    Location:
    London
    #3
    I see what you mean. I'm new to doing this on mac and would prefer to do it something else.

    With something like textwrangler, would I just program like on notepad and get the same results?
     
  4. mnkeybsness macrumors 68030

    mnkeybsness

    Joined:
    Jun 25, 2001
    Location:
    Moneyapolis, Minnesota
    #4
    Get Textmate!

    All of the macros, snippets, tab-completion, etc make it so much faster to write code in (for many, many languages).

    BBEdit used to be my editor of choice until I got a chance to really see how useful Textmate's features are.
     
  5. SrWebDeveloper macrumors 68000

    SrWebDeveloper

    Joined:
    Dec 7, 2007
    Location:
    Alexandria, VA, USA
    #5
    Hmmm.... saving as HTML should have worked.

    If problems still persist after trying another editor, make sure you FTP (upload) the saved document as ASCII text, not binary, and do not use any options to translate text to HTML entities which does things like change < to < and > to > which would stop your scripts from being parsed in the server.

    Feel free to get a more feature packed editor if you prefer WYSIWYG editing, but for JS and hand written code any text editor will do, really, and add the .html or .php or whatever extension you normally use on your server to the filename if not there already.

    -jim
     
  6. chipandegg thread starter macrumors regular

    chipandegg

    Joined:
    Oct 3, 2007
    Location:
    London
    #6
    Smultron/TextWrangler

    These two apps were recommended to me for html and JavaScript.

    I have entered my code correctly and saved as an .html file to the desktop. Though when I go to open the file so that I get a prompt box to appear and Safari to open. The actual app will open and my finished code is not run

    Does anybody have any idea on how to change this.

    On Textedit I managed to run my code perfectly, it did what I wanted it to do (open a prompt box and give a result in Safari)

    Any idea on how to do what I did in TextEdit on TextWrangler or Smultron. As I can already see that these two apps are much better for what I'm doing than TextEdit.

    Many Thanks
     
  7. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #7
    Would you be able to post the code you're using? I'm not quite following what your code is suppose to be doing and what technique you're using. It's likely to be a simple fix.
     
  8. SrWebDeveloper macrumors 68000

    SrWebDeveloper

    Joined:
    Dec 7, 2007
    Location:
    Alexandria, VA, USA
    #8
    I've created a W3C validated test script in HTML (attached to this reply) which I loaded from my desktop and displayed JavaScript without issue in Safari 3.1.1 with default settings. Try my script in your browser, renamed with .html extension on the end since this forum does not allow .html uploads. If mine doesn't work on your platform, it's something with your Safari settings most likely.

    Otherwise please upload your HTML file fully intact so I can looksee, or if you feel uncomfortable doing that upload it the W3C validator here and fix any errors and try it again on your own.

    If it doesn't validate, the test isn't fair.

    -jim
     

    Attached Files:

  9. chipandegg thread starter macrumors regular

    chipandegg

    Joined:
    Oct 3, 2007
    Location:
    London
    #9
    My html is fine as it has already worked in TextEdit, prompt window appeared and got some output.

    Though I copy and paste from TextEdit to TextWrangler, save as html, go to click on the icon and TextWrangler opens up, thats the part I don't understand. I should get the same result as when I did it in TextEdit.

    Heres my noob code anyway (you'll probably notice things , lol)

    HTML:
    <html>
    <head>
    <script language = "JavaScript">
    
    var response
    
    response = window.prompt('are you having a good day?','');
    if (response == 'yes')
    {
    	document.write('Glad to hear it')
    }
    else
    {
    	document.write('maybe 2moro will be better')
    };
    document.write('thank u')
    
    
    </script>
    </head>
    </html>
     
  10. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #10
    Are you saying that TextEdit provides you with a prompt from the JavaScript? I've never seen it do that. You should be testing the JavaScript in Safari or Firefox. When I open your code in Firefox or Safari I get the prompt and it writes out what you'd expect in the browser window.

    As far as "go to click on the icon and TextWrangler opens up" I believe that's because TextWrangler is associating itself with that file and so will open TextWrangler rather than a browser. If I follow correctly anyways. I'm still having a little trouble following your work flow from each program, but that may just be me. I know describing this type of thing can get tricky.
     
  11. chipandegg thread starter macrumors regular

    chipandegg

    Joined:
    Oct 3, 2007
    Location:
    London
    #11
    Thanks for helping

    when I do html and javascript in TextEdit. I go to save as, textEdit will give me a choice of file formats, from there i choose html. It is now saved to the desktop, the file looks like a safari compass on the desktop

    Oh when I said prompt box, thats cos I programmed it in, so when i click on the file I get the box showing, unlike when I do the exact same thing in TextWrangler. Textwrangler opens but not Safari, yet the TW file is html too

    Many Thanks once again
     
  12. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #12
    OK, I think it's just a file association issue that you're describing. Once you have the file written in TextWrangler and save it to the desktop or wherever right-click on the file and choose Get Info. Then go under the Open With section and change it to Safari and then close that window. Then when you double-click to open the file, it should open Safari instead of TextWrangler.
     
  13. deputy_doofy macrumors 65816

    deputy_doofy

    Joined:
    Sep 11, 2002
    #13
  14. chipandegg thread starter macrumors regular

    chipandegg

    Joined:
    Oct 3, 2007
    Location:
    London
    #14
    Thanks for the advice everybody, problem solved. I'm thinking why didn't I do that in the 1st place,
     
  15. vinothjaguva macrumors newbie

    Joined:
    May 20, 2008
    #15
    Open a application in MAC using JAVASCRIPT

    Hi

    Please help me on this.

    How to open a application like word or excel or quark or indesign etc., in MAC using javascript through html.

    When i click the [open a file] the application needs to open with a relevent file.

    Thanks in advance.
     
  16. chipandegg thread starter macrumors regular

    chipandegg

    Joined:
    Oct 3, 2007
    Location:
    London
    #16
    Dude I wouldn't know sorry, though many others will
     
  17. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #17
    JavaScript has nothing to do with it. Setup a link with the href as file:///path/name/to/file.doc It'll be up to the operating system to decide which application to open depending on file association. And of course this only works on a local setup, not the Internet.
     
  18. vinothjaguva macrumors newbie

    Joined:
    May 20, 2008
    #18
    Hi,

    If i use "file:///path/name/to/file.doc" incase anyone is changed the open with property to other application(instead of word to wordpad), what will happen, the program will open the file in the current open with setting, in that case the file will get damage.

    actually i was used this code to open a application but it was not open, any one can help me on this.

    var url = "telnet:eek:sascript -e \"tell application \"Adobe Indesign CS2.app\" to open\""

    Thanks in Advance.
     
  19. SrWebDeveloper macrumors 68000

    SrWebDeveloper

    Joined:
    Dec 7, 2007
    Location:
    Alexandria, VA, USA
    #19
    If this is on a Windows computer follow the instructions on this web page:

    http://www.codetoad.com/forum/15_24468.asp

    Requires Active-X controls which is Microsoft proprietary. Read that entire thread for assistance on making this work with Linux and also any requirements such as browser file association setup.

    One other suggestion is upload it to Google documents and simply include the URL in your HTML, assuming the user has Internet access. Google docs does make opening Word documents online easier than simply downloading or opening locally based on the associated MIME type on the user's local computer which is how it normally works (and was discussed earlier).

    Remember, no single solution works on all platforms. I've given two solutions here, hope this gets you started.

    Note: The OP had their question answered earlier, vinothjaguva posted a new question, maybe a moderator should split this topic.
     
  20. sawmaster macrumors regular

    #20

    I know this thread is old, but I recommend any searchers this: Coda by panic.com.
     

Share This Page