Link to home
Start Free TrialLog in
Avatar of YZlat
YZlatFlag for United States of America

asked on

Displaying flash file from a page inside a div using AJAX


I have a page that utilizes master page and has a <div> on it in which it displays asp.net page that displays two flash files. My main page is Default.aspx and page displayed inside a <div> is Page1.aspx

If I open Default.aspx, the Page1.aspx displays correctly except for flash file which is displayed as a grey box. But if I open Page1.aspx in a browser, it displayes everything fine. How can I make it display correctly inside a <div> on Default.aspx page?
SOLUTION
Avatar of wellhole
wellhole

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of YZlat

ASKER

that's the thing - page itself displays fine. The flash file displays without an issue, but inside the <div> it does not. I believe it might have something to do with flash file path
Avatar of wellhole
wellhole

Again, you must see the live page html. It doesn't matter how the page looks at the moment.

In firefox, navigate to Default.aspx and Edit the <div></div> in question. Delete everything. Then, add the flash object manually. See if that works.
Avatar of YZlat

ASKER

That's not really an option for me because flash is generated programmatically, using javascript
So then take the html code for the flash object from the webpage directly.
Avatar of YZlat

ASKER

What I did is opened page source for Page1.aspx and saved it as html file. When I opened this html from IE, I got the same result as I did in Default.aspx page. I had to select "To help protect your security IE has restricted this file from showing active content that could access this computer" from the top of the page. That might be the same reason why it does not display on Default.aspx.

Do you know how can I enable active content?

You should be developing on firefox to take advantage of firebug. As far as I know, most web developers do.

As to answer your question, add <!-- saved from url=(0014)about:internet --> to the top of the html file.
Avatar of YZlat

ASKER

how can I debug in firefox? i've never done that before
Get firefox, install firebug addon, restart firefox, look for a bug on your firefox window information bar.
Avatar of YZlat

ASKER

I installed the firebug addon and restarted firefox. Then i opened my web page in firefox and I still don't see flash files inside the div and get no errors
That's not what I asked from you. See my post 33628810.
Avatar of YZlat

ASKER

check my post 33629506
Avatar of YZlat

ASKER

besides, there is no way for me to edit the <di> since it is empty because data is loaded using AJAX so it's not showing up in HTML
After your web page is loaded, you're telling me that your javascript is still generating the code for the flash? Should that not already be loaded? Firebug lets you EDIT the html LIVE. If javascript alters the html, then you'll see that exact code in firebug. What are you confused about?
Your <div> couldn't possibly be empty because, you say so yourself, ajax has loaded your <div> with Page1.aspx. If it's empty, you should not be able to tell that Page1 loaded inside the div but the flash is not displaying as your question states.
Avatar of YZlat

ASKER

it loads the page but if I view source code, the div does not contain any html code beacuse it is loaded through AJAX
Please use firebug to EDIT the html LIVE. View source does what it says; It lets you view the source. It's not for viewing the current html you're looking at. If you installed it, there should be a new icon in your firefox status bar.
Avatar of YZlat

ASKER

well, how can I use firebug to edit live html?
You click on the firebug, goto the html tag, and start editing. I don't know how anyone can explain this any easier.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of YZlat

ASKER

yes, Page1.aspx is a complete web page that is not using Master page. Default.aspx, on other hand, does use a master page.

And this code below is used to load Page1.aspx into a div on Default.aspx:


function ajaxpage(url, containerid){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false

page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
}

page_request.open('GET', url, true)
page_request.send(null)

}

function loadpage(page_request, containerid){

if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
var divElement = document.getElementById(containerid);
divElement.innerHTML = '';
try {
divElement.innerHTML = page_request.responseText;
}
catch (e) {
var wrappingElement = document.createElement('div');
wrappingElement.innerHTML = page_request.responseText;
divElement.appendChild(wrappingElement);
} 


}
}

Open in new window

In the future please use the snippet box for code snippets.  It make the comment and code easier to use and read.

Thanks for the answers.  Change page1.aspx (or make a new page to use) so it sends just the html that would go in the div.  Remember the result should still be a valid html page and it isn't valid to have a complete html page in a div tag.  Let's see if that fixes the problem.  Let me know if you have a question about doing it or what I said.

bol

p.s.  I am going to move the code into a snippet (I am a zone advisor so have the tools to do it).
Avatar of YZlat

ASKER

What do you mean by sending just the html that goes into div? To remove <html> and <body> tags?

>> To remove <html> and <body> tags? <<

Yes and probably more.  You need to keep in mind what makes a page valid for html.  In the end that is what you have in the browser and the ajax part needs to make changes to the page that will still result in a valid web page.  I mentioned using a div as a "container" so the html that is sent in that container must fit with the rest of the page to make a valid web page.  Remember the "a" part because it is just one page since you no longer have frames/iframes.

Let me know if this still isn't clear or you have a question.

bol
Avatar of YZlat

ASKER

btw, I used Firebug to view the generated html and saw that when I open Page1 directly I get an <embed> tag with flash file in there, but when I open Default.aspx and Page1 is displayed inside the <div>, I get Javascript code that generated <embed> tag instead
Avatar of YZlat

ASKER

P.S> removing <html> and <body> tags had no impact
>> removing <html> and <body> tags had no impact <<

Do you have valid HTML now?  That is important to verify or anything else you may try could be impacted by bad html.

>> I get Javascript code that generated <embed> tag instead <<

That is what I was afraid of and discussed some in the comment at http:#a33667071 .  Starting with the paragraph "Before getting into this too much ..."  What you mentioned confirmed this.  You will have to do some extra Javascript code to create the element, not just fill in the html/javascript.  I made some suggestions and mentioned what I thought with the info provided in that same comment.  Please review it so I don't have to retype.  Let me know how that helps or if you have a question about it.  It included the way I would recommend trying to do this but I don't know how well that works with how you have this all designed and your "pages" for the content div.

bol
Avatar of YZlat

ASKER

Looks like there is nothing I can do because of the issue with flash you have mentioned.

You have been very helpful. Thanks!