| | |
dynamic content does not fire javascript.
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
Hi I am working on a little project I'd like to call post database and I got a little problem. when user clicks a page number, I bring html content from server and add it to page. And I can see the new content on the page. But if new html content has some java script it does not run.
you can see the example on
postdatabase.appspot.com
go to tutorials page, and click page 3 . new page will come. including following alert inside
But it show alert window. Somehow browser does not fire javascripts.
Here is my guess: it does not work because you can not use javascript to shape pages after page load.(I just made that up. but there is no other logical explanation I can come up with.)
you can see the example on
postdatabase.appspot.com
go to tutorials page, and click page 3 . new page will come. including following alert inside
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
alert('asdf');
Here is my guess: it does not work because you can not use javascript to shape pages after page load.(I just made that up. but there is no other logical explanation I can come up with.)
•
•
Join Date: Jun 2009
Posts: 4
Reputation:
Solved Threads: 1
Hi, you have to add an Id to the script
and when the dynamic content is load you have to find the script
:-)
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<script type="text/javascript" id="evalMe"> alert('asdf'); pdbinit(23001); </script>
getElementById('evalMe') and apply eval.:-)
First of all thank you for quick response.
Let me tell you what I am trying to do.in this project. I go to settings page and create a new wall. then in my page (in this case tutorial page 3). than I call pdbinit function. which writes two div elements with document.write() and then fill inside divs with the data it gets from server. now here is the problem. if I use eval ,I wont be able to use document.write because My text will already be converted to elements and added to htmldom. so what I need is to use document.write in the text of innerhtml.
I simplified the question here is the code.
Here I have a button when I click it , I inject an html (including some script) into the page. but script does not run. how can I run this. I also added a button to run document.write. if you press it it will run document.write. which will overwrite the content of the page. this has to be called by browser only when browser convert text to htmldom elements. (I am just guessing right now.)
Let me tell you what I am trying to do.in this project. I go to settings page and create a new wall. then in my page (in this case tutorial page 3). than I call pdbinit function. which writes two div elements with document.write() and then fill inside divs with the data it gets from server. now here is the problem. if I use eval ,I wont be able to use document.write because My text will already be converted to elements and added to htmldom. so what I need is to use document.write in the text of innerhtml.
I simplified the question here is the code.
HTML Syntax (Toggle Plain Text)
<html> <head> <script type="text/javascript"> function inject(targetDiv){ var content = '<b>This is the text before script</b> <script type="text/javascript">document.write("<br>This part is written via script")</script'; content +='>';//I am adding this here to broke </script!> tag targetDiv.innerHTML = content;} </script> </head> <body> <div id="myDiv"></div><br> <input type="button" value="inject HTML" onclick="inject(document.getElementById('myDiv'))"/> <input type="button" value="Call Document.write after page load" onclick="document.write('Calling document.write after page load')"/> </body> </html>
Here I have a button when I click it , I inject an html (including some script) into the page. but script does not run. how can I run this. I also added a button to run document.write. if you press it it will run document.write. which will overwrite the content of the page. this has to be called by browser only when browser convert text to htmldom elements. (I am just guessing right now.)
Try this one:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<html> <head> <script type="text/javascript"> <!-- var inject = function( targetDiv ) { targetDiv.innerHTML = ""; var content = "<b>This is the text before script</b>\n"; var script = document.createElement("script"); script.type = "text/javascript"; script.id = "script1"; script.innerText = "function injectFunc() { document.write( '<br>This part is written via dynamic injected script!' ); }"; targetDiv.appendChild( script ); targetDiv.innerHTML += content; }; //--> </script> </head> <body> <div id="myDiv"></div><br> <input type="button" value="inject HTML" onclick="inject(document.getElementById('myDiv'))"/> <input type="button" value="Call Dynamic Function" onclick="injectFunc();" /> </body> </html>
![]() |
Similar Threads
- WebRequest Capture Dynamic Content (ASP.NET)
- Dynamic web (JavaScript / DHTML / AJAX)
- Dynamic Content Based on Domain? (IT Professionals' Lounge)
- Programming FAQ - Updated 1/March/2005 (Computer Science)
- Dynamic iFrame height, not working in ie without refresh. (JavaScript / DHTML / AJAX)
- Combining Static & Dynamic content (JSP)
- Making T.Greer's JavaScript-synthesised combobox dynamic (JavaScript / DHTML / AJAX)
- Arizona Web wants reviews too! (Website Reviews)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Change the magnification level of a div with contents inside it
- Next Thread: What is the difference between these
Views: 1010 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
acid2 ajax ajaxcode ajaxhelp animate array automatically autoplay beta boarder box bug button calendar captcha card cart codes column cookies createrange() css cursor date debugger decimal design developer dom download dropdown element enter error events firefox firehose flash focus form frameworks getselection google gwt html htmlform iframe image() index java javascript javascripts jawascriptruntimeerror jquery jsp listbox maps marquee masterpage menu microsoft mimic mp3 mp4 offline onmouseover parameters php player post problem programming progressbar prototype rating redirect regex safari scale scriptlets search select size sources sql starrating text textarea toggle twitter validation variables w3c web website window windowofwords windowsxp xml xspf





