Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

dinggus

macrumors 65816
Original poster
Jan 17, 2012
1,309
63
How can I run a javascript just from my computer? I'd like to test a script out.
 

Dunmail

macrumors regular
Mar 27, 2009
224
4
Skipton, UK
Thanks, do I just enter the script info or what? Can I PM you the script code?

Simply create a web page and include the code. Save the file locally and double click it to open in your browser. If your script relies on certain elements being on the page then you'll have to add them.

Code:
<!DOCTYPE html>
<html>
<head>
<!-- put CSS links and meta tags here -->
</head>
<body>
<!-- Any elements you need for your script to work -->
<script src = "path to your script"></script>
</body>
</html>

Depending on how you've written your script you may have to add an event handler to the body:

Code:
<body onload="entryfunction()">

Better is to use the IIFE (Immediately Invoked Function Expression) format at the foot of the page:

Code:
<script>
(function (){
// All your code here or call your entry function.
}());
</script>
 

MyNameIsDave

macrumors member
May 28, 2012
37
0
Blighty
If your code depends on other libraries such as jQuery, you can try it out online at jsfiddle.net

You can then share it with other people if you want to show them about your code (e.g. to get help with it).
 

dinggus

macrumors 65816
Original poster
Jan 17, 2012
1,309
63
If your code depends on other libraries such as jQuery, you can try it out online at jsfiddle.net

You can then share it with other people if you want to show them about your code (e.g. to get help with it).

Thanks I shared it with Dunmail and his response was:
look at that code looks like it is a subsystem that gets called from something else. It relies on jquery so you'd need that. Not sure what else it might need.

Either ask whoever you got the script from or create a web page with buttons that when clicked call the functions in the code.

So, now I'm stuck because I how no clue how who to get ahold of for the script, or create a web page with buttons to call the functions.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.