PDA

View Full Version : Doesn't work: Ajax loading a page with inline javascript code.



alexhu01
5 Feb 2008, 10:22 AM
Hi, Guys,

I try to load a html page that contains inline js code in and assign it to a div.innerHTML. It doesn't work even though I set scripts to true. Here is what I did.
s.el = new Ext.Element(document.createElement('div'));
s.el.applyStyles('overflow:auto');
s.el.addClass('sample-slider');
s.el.enableDisplayMode();
s.el.load({
url:'http://localhost/includes/test/inlinejs.htm',
scripts: true,
text: 'loading test...'

});
s.el.appendTo(box);
=============================================================
inlinejs.html is like this:

<p> Test inline script</p>
<script language="javascript">
document.write("test1");
</script>
<p> wait...</p>
<script language="javascript">
document.write("test2");
</script>
<p>final stage </p>
==============================================================
there are two inline js statements get executed: document.write("test1"); and document.write("test2");

run the test what I got is just "test1test2", seems other pieces are missed or overwritten.

Thanks,
Alex Hu

devnull
5 Feb 2008, 12:45 PM
you are expecting it to somehow guess that instead of writing to the body (document.write) you want it to write into the element that you called load() on? thats not how javascript works... and you should not be using document.write with an Ext app.

alexhu01
5 Feb 2008, 7:05 PM
Thank you for your reply, devnull, it's just an example, my task is to go to grab the content in an html page that contains inline javascript and show the content inside a div element. From your reply, I think I can assume that extJS doesn't have the functionality to handle this kind of situation.

Alex



you are expecting it to somehow guess that instead of writing to the body (document.write) you want it to write into the element that you called load() on? thats not how javascript works... and you should not be using document.write with an Ext app.

devnull
6 Feb 2008, 9:18 AM
Ext can do exactly what you want, but I can guess from your reply that you want to apply your previous non-webapp javascript coding to this and will be unwilling to learn the Ext API to do it the right way.