Results 1 to 4 of 4

Thread: Dynamic Ajax Content DIVs don't execute scripts

  1. #1
    Join Date
    Jul 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Dynamic Ajax Content DIVs don't execute scripts

    1) Script Title: Dynamic Ajax Content

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...jaxcontent.htm

    3) Describe problem: I can't execute <script> tags inside of a div where a page was loaded. Example: test.php has <script>alert('test');</script> in it. When viewed externally, the alert pops up. When loaded into a div, nothing happens.

    Is there a way to allow <script> tags to execute inside of a div? I really need this to happen.

    EDIT: Apparently, responseText (as in page_request.responseText) doesn't evaluate scripts. Is there a way to override this?
    Last edited by EdBoy; 07-15-2007 at 11:56 PM. Reason: new info

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,496
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    You are right, of course. However, it really depends upon what you want to do with javascript at the time that the external content is loaded. Obviously, you are not ultimately trying to alert 'test'. If the script is something that normally would run onload of a page, I would direct you here:

    http://www.dynamicdrive.com/forums/s...ad.php?t=17426

    If you need a more involved solution to the onload problem, there is also:

    http://www.dynamicdrive.com/forums/s...ad.php?t=13003

    However, if you just want to load up a script that requires no initialization and have it available, the Dynamic Ajax Content script has the loadobjs() function for just that purpose. Read the demo page for Dynamic Ajax Content thoroughly for information on its usage.

    Finally, if all you really want to do is alert 'test' (from the demo page, addition red):

    Code:
    <a href="javascript:alert('test');ajaxpage('test.htm', 'contentarea');">test</a>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jul 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile

    Ah, I see.

    With a little IRC scouting, someone gave me this nifty trick which fixed all the problems. Thanks for clarifying it, though.

  4. #4
    Join Date
    Aug 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default having difficulty also

    I'm also having difficulty with external scripts and this ajax code.

    I am using external .js files that have no <script> tags. It's for a vertical image scroller within a div. I've tried adding it to the main .js file, pasitng it in to head of the host file with <script> tags, and using the javascript:loadobjs('cool_slider.js') method and my images in the slider will not scroll.

    Here's my post.
    http://www.dynamicdrive.com/forums/s...ad.php?t=23716
    Last edited by jscheuer1; 08-15-2007 at 02:35 AM. Reason: fix link

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •