MMK
MMK

Reputation: 605

Load content and the separate the content V/S load iframe?

I am working with jquery and i have an issue concerning loading content from a server, separating the content from the rest of the content already on the page and then immediately when the content(from the server) has loaded, do some dom manipulation.

The problem i am getting is some css styles are being overridden.

I am faced with two situations:

1) From what i read you can load content from a server using the jquery load() method and then provide a callback that will run when the content finishes to load. However i am unable to separate the content styles and some javascript functions from running.

Here is the jquery code i am using:

$('#ContentIn').load('the_url_of_the_content_to_load', callback_function_to_run())

But then with situation one i am unable to separate the contents from the server from that already on the page.

2) Then i tried using an iframe like so:

$('#ContentIn').append( '<iframe src="' + object.responseJSON.the_url + '"></iframe>' );

Note that i am using Ajax to get a url and then i am successfully injecting the iframe into the body of the current page.

But then with situation two i am unable to run a function as soon as the iframe finishes loading the contents.

In hope of an answer,

MMK

Upvotes: 0

Views: 64

Answers (1)

Sharique Hussain Ansari
Sharique Hussain Ansari

Reputation: 1456

you can try this:-

$('#ContentIn').append( '<iframe onload="myfunction()" src="' + object.responseJSON.the_url + '"></iframe>' );

function myfunction()
{
//write your code here
}

Upvotes: 2

Related Questions