Jump to content

[SOLVED] Cant Execute


jaymc

Recommended Posts

Im using ajax to load some content in a div, working fine

 

However, the content which I am placing in the div contains some javascript which I need executing

 

Lets just for instance say the content I wanted to dynamically load in the div was this

 

Hello World

<script type="text/javascript">

alert('hi');

</script>

 

Question is, how to get the alert to execute in its enviroment

 

Im justing alert as an example by the way

Link to comment
Share on other sites

I don't think that is a good process. Since you are populating the text via JavaScript, just run that alert (or function or whatever) within the code that receives/populates the data. One trick would be to use a delimeter to separate the text from the javascript you want to act upon.

 

Example:

<b>Hello World|hi</b>

 

Then just use the "|" to split the data. Use the first part to populate the div and the second part to use in the alert (or for whatever purpose you need)

Link to comment
Share on other sites

ok I think I may have confused you with the alert thing so I will just give the real reason

 

The javascript actually contains swfovject code, you know that script to stop ie having the click to enable controls

 

So my mission is to load a new flash movie into to div but it must be done via the parametres passed which of course is through javascript

 

The problem is getting that javascript to execute which generates the flash movie.

 

Dont forget its in another frame just invade thats a problem

 

Thanks

Link to comment
Share on other sites

Here

 

<script type="text/javascript">

	var fo = new FlashObject("magic_beans.swf", "movie", "88", "24", "7", "");
	fo.addParam("allowScriptAccess", "sameDomain");
	fo.addParam("quality", "high");
	fo.addParam("FlashVars", "playlistfile=config/PlayData.php?id=198&configurationfile=config/configuration.xml");
	fo.addParam("wmode", "transparent");
	fo.write("flashPlayer");

</script>

 

I click a link in FRAME 2, that sends a request to a page which returns the above javascript. AJAX must then place that script and execute it in FRAME 1

 

How can this be done, as the script above is pretty much being treated as plain text, even though it doesnt actually display in plain text

 

Its not being parsed basically

Link to comment
Share on other sites

No confusion, I understood the alert was just an example. The process I described above is still valid. Create a function on the page to run the swfovject script, but create it to accept parameters for whatever data will be variable. Then in the data that is created from the AJAX request add those parameters using a delimeter. Then the JS that handles the AJAX return value can parse the return value and call the function with those parameters. In fat, I would create a single function that would take the return value and 1) parse the data, 2) Populate the div and 3) Run the swfovject code.

Link to comment
Share on other sites

ok I think I understand

 

I will handle the data inside the Ajax function itself and populate it accross rather than from within

 

Doing that though I will have to mess about with swfobject so it places the flash in a div in another frame

 

Thats the only way right or have I not understood your idea

 

Your way it seems like I can execute a function in one frame from another, for example

 

Window.theframe.swfobject(parameters

)

Link to comment
Share on other sites

That sounds about right. Although I don't understand your comment " I will have to mess about with swfobject so it places the flash in a div in another frame". Weren't you already placing the flash object in another frame?

 

If you are running the AJAX request from one frame and using it to populate the Flash in another, you may need to get a little creative. A quick liik at the SWFObject documentation shows that you indicate the DIV to place the content in using a line like this:

   so.write("flashcontent");

 

So, you can't indicate a div in another frame. What you cn do is have teh AJAX function in one frame and then use the return data and call a custom function in the other frame which will then run all the necessary code "locally" within that frame.

 

FRAME 1

- Make AJAX call and get return data

- Call function in FRAME 2 passing the return data as a parameter

 

FRAME 2

- Function1 takes the AJAX return data and parses it into the individual elements (Flash object and parameters for the SWFObject)

- Function 1 writes the Flash object to a div

- Function 1 calls Function 2 (in the same frame) and passes the SWFObject parameters

- Function 2 will run the code for SWFObject

 

Example for function 2 (assuming the flash file, heihgt & width are the only variable elements)

function setSWFObject(swfFile, width, height) {
    var fo = new FlashObject(swfFile, "movie", width, height, "7", "");
    fo.addParam("allowScriptAccess", "sameDomain");
    fo.addParam("quality", "high");
    fo.addParam("FlashVars", "playlistfile=config/PlayData.php?id=198&configurationfile=config/configuration.xml");
    fo.addParam("wmode", "transparent");
    fo.write("flashPlayer");
}

 

EDIT: You can cll a function in another frame, but I haven't done that in a while and don't remember the correct method of making the call.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.