SitePoint Sponsor |
|
User Tag List
Results 1 to 8 of 8
Thread: Pulling in HTML
-
Jun 11, 2007, 07:07 #1
- Join Date
- Feb 2003
- Location
- Knoxville, TN
- Posts
- 531
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Pulling in HTML
i'm using AJAX to pull in HTML from an external HTML document (cause i don't wanna use iframes). thing is, the javascript within the <script> tags doesn't execute when pulled in.
i would like for the javascript to execute when the HTML is brought into the page.
even a simple...
<script type="text/javascript">
alert("test");
</script>
...doesn't work. and i've tried window.onload = function() {}, too.
-
Jun 11, 2007, 08:09 #2
- Join Date
- Jun 2004
- Location
- Copenhagen, Denmark
- Posts
- 6,157
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
That won't work. Why don't you use iframes?
-
Jun 11, 2007, 11:25 #3
- Join Date
- Feb 2003
- Location
- Knoxville, TN
- Posts
- 531
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
actually - it can be done... using AJAX i can do a responseXML and grab the <script> tag and run an eval() on it. i'm pulling the responseText but i'm having problems right now getting the <script> tag using req.responseXML.getElementsByTagName("script")[0].firstChild.data;
-
Jun 11, 2007, 12:57 #4
- Join Date
- Jun 2004
- Location
- Copenhagen, Denmark
- Posts
- 6,157
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
responseXML is only available, if the response is content-type xml
-
Jun 11, 2007, 13:05 #5
- Join Date
- Sep 2005
- Location
- Tanzania
- Posts
- 4,662
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
But if you override the mime type you can use it.
http://developer.mozilla.org/en/docs...MimeType.28.29
-
Jun 11, 2007, 15:09 #6
- Join Date
- Sep 2005
- Location
- Sydney, NSW, Australia
- Posts
- 16,875
- Mentioned
- 25 Post(s)
- Tagged
- 1 Thread(s)
Why are you using Ajax or iframes for loading additional JavaScript when you can just add the script tag to the page and pull the script in automatically. Pulling in JavaScript by adding a script tag to the page is one of the four ways of updating a web page from the server without reloading the page (ajax, iframes, and images that run server side code being the other three)
Stephen J Chapman
javascriptexample.net, Book Reviews, follow me on Twitter
HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
<input name="html5" type="text" required pattern="^$">
-
Jun 11, 2007, 15:46 #7
- Join Date
- Feb 2003
- Location
- Knoxville, TN
- Posts
- 531
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
i'm using ajax because i have a <div> that i'm populating with various html files on the fly - yet each html file needs it's own javascript to run when it's loaded. i don't wanna use iframes cause i think they're a pain to mess with it and loading into a div i can make it conform to the page much easier.
i've had zero problems with bringing in the html files or styling...just having the html document's javascript execute.
-
Jun 12, 2007, 10:43 #8
- Join Date
- Feb 2003
- Location
- Knoxville, TN
- Posts
- 531
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
that helped me out a ton, man...thanks! here's what i did, basically...
in the ajax function
Code:pagereq.onreadystatechange = loadpage; pagereq.open("GET", url, false); pagereq.overrideMimeType("text/xml"); pagereq.send("");
Code:if (pagereq.responseXML.getElementsByTagName("script").length) { alert(pagereq.responseXML.getElementsByTagName("script").item(0).innerHTML); }
Bookmarks