javascript and applescript

hi, I am not new to AppleScript but very new to javascripts, I know this forum is for applescripts only but its still the best forum I know. So any idea or direction will help.

I am trying to fill out a form using applescripts and do javascript commands, and I have notice that all submit buttons include a tag called “OnClick”. My question is… Were is the code in the OnClick coming from?

for example take a look at this page:

http://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_ev_onclick

in this page the button copy text activates a string called “copyText()”

Were is all the code? does it load at the beginning? is it in the server? how can I see and read this code? can I hijack this code and activate my one javascript once I made a few adjustments?

Thank you for your time!

Brian

Hi Brian,

This is the code you’re talking about. This function is triggered with the onclick.

Not sure if this will help you:- http://macscripter.net/viewtopic.php?id=41783

HTH

doh! Yes! thank you for replying! I think the example I put was to easy! other webpages don’t have the code any were! as you can see the function includes the name copy my page does not! You just fill out the page then press a button that calls a waterer() function and I have no idea how to view the code! I will se the link you gave me! thank you very much for time!

Brian

Hi Brian,

The code for the waterer() function may not be present in the visible source code for the web page. The function maybe part of a .js file that is loaded, or ‘included’, when the webpage is called by the browser. There are other ways that the function could be loaded.

If you view the source code for the page and do a search for .js it may point you in the right direction.

HTH

The code is running in an JavaScript engine inside your web browser. Most web browsers have their own JavaScript interpreter for some good reasons. Google has the fastest JavaScript interpreter called V8 and is open source. Apple Safari and Google Chrome share the same HTML engine, they don’t have the same JavaScript engine.

For the curious ones: Safari uses JavaScriptCore, version Nitro. Which is an improved version of the old slow JavaScriptCore versions when Safari was launched.

It depends where your script is located (head or body). Either way it is loaded while loading the web page, not when you click on a button or something.

No, like everything you see in your browser it’s locally stored. It’s only downloaded from a server if needed. PHP for instance is server side scripting, JavaScript is client side.

Look up into the source code of the page, everything is there and nothing is hidden. However you can compress huge libraries in JavaScript to save up a few kilobytes which makes them hard to read.

[code]function copyText()
{
document.getElementById(“field2”).value=document.getElementById(“field1”).value;
}

function emptyText()
{
document.getElementById(“field2”).value=“”;
}[/code]
can also be written down as

function copyText(){document.getElementById("field2").value=document.getElementById("field1").value}function emptyText(){document.getElementById("field2").value=""}

which is much harder to read.

Also you don’t have to embed JavaScript code into your page but you can store it externally like you do which images and css files for instance. But like images and css files, you can look at it’s reference and download it manually. Look at this page’s source code you’ll see in the header a reference to highslide.js when you open the url in a new page you see the source code.

No, first of all it would be the largest security leak in history. You need access to the files on the webserver, some are dynamically created and some are static. That means on MacScripter you need to rewrite php code or external javascript files and re-upload them to the server.

Thank you all for this excellent feedback! I really appreciate your help! I hope I can be of service in the future! once I find a way of to highjack .js hahaha! just a joke! :slight_smile: