Submit form using javascript

Simply to submit a form using javascript you can write:

In the following code you will see a special case where the form is not appearing directly on the page but through an iFrame element.

 

This code tested on Chrome, FF, IE and Safari Windows.

 

Source Code

Call container page function from child iframe

The simplest way i got to call a function that exists in the iframe container page is using:

 

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>title>
head>
<body>
    <form id="form1" runat="server">
    <div>
        <script language="javascript" type="text/javascript">
            function AlertFromParent() {
                alert('I am parent');
            }
        script>
        <iframe src="IFramePage.aspx" id="myIframe">
        iframe>

    div>
    form>
body>
html>

 

 

Notes:

– This function is working just if the 2 pages ‘the parent and the child’ are in the same domain name, and if they are in 2 different domains you will get permission denied error.

– If you will run the javascript code inside the iframe on load ‘as in the previous example’, make sure that the parent script function exists before the iframe tag, because the iframe will break loading the page till it finish loading and everything after it will wait till it completely loads.

Flash Javascript communication first look

 

I did a fast research about how to make flash interact with the container website, and i collected some good information.

4_flash

There are 2 main techniques to implement communications between flash and the container website:

Example: http://www.kongregate.com/developer_center/docs/kongregate-api

1- Client API technique:

Reference: http://www.adobe.com/devnet/flash/javascript_api.html

Using this technique, the flash will communicate with the website through JavaScript.

So in brief, the flash can send and receive variable from the website using Javascript, and for this first research I got 2 main ways to make flash interact with Javascript:

a- Using the ExternalInterface which exist in the action script classes, http://livedocs.adobe.com/flex/3/langref/flash/external/ExternalInterface.html, http://kb2.adobe.com/cps/156/tn_15683.html#about,

Example: http://jodieorourke.com/view.php?id=122&blog=news

b- Using normal Javascript calls as in this example: http://www.permadi.com/tutorial/flashjscommand/ which describes the main functions to interact with the flash using Javascript.

2- Server API technique:

Example: http://www.puarcade.com/demo/classic-games/snake

Using this technique, flash will call the server side APIs directly, and will post variables to the API URL, also there is another way is to send these variables using Querystrings, which will not be the right way all the time and may be not possible in some cases ‘put in mind for example the max number of query string characters’.

Conclusion:

Most of game websites use the server side APIs, but big famous website give both options, server or client side APIs. http://www.kongregate.com/developer_center/docs/kongregate-api

Server Side advantages from my point of view:

– More secure calls.

– Works whatever the user enabled javascript in the browser or not.

– No problems with different browsers compatibilities.

Client Side advantages:

– Middle layer, between the server side code and the flash, which encapsulates the server side methods and don’t let the flash call the server APIs directly but will be through this JS layer.

– Gives the ability to submit values to the server using Ajax style ‘without refreshing the whole page’.

– The flash will need less information from the website, as the Javascript code will handle most of the common variables ‘such as the current user, the current page URL, …’.

By the way in both cases we will need to implement the server side API first and then will let the Javascript and flash code interact with this APIs.

http://stackoverflow.com/questions/3179476/whats-the-best-practices-to-let-flash-files-communicate-with-my-website