Jump to content

http get a script tag?


pnj

Recommended Posts

Is it possible in IE to load an element with an embedded script tag via http get?  I can get such a script to run in Firefox, but not in IE.

The http get callback function looks like this:
function proc_rep () {
  if (http.readyState != 4) return;  // not finished loading
  p = document.createElement("div");
  p.innerHTML = http.responseText;
  par.appendChild (p);
}

The file being loaded could be as simple as a script tag with a window.alert() call.

In fact the script is more complicated, but even this simple example works in Firefox, but not in IE.  Any thoughts?

I know that I can load a file in IE if its content is ONLY javascript code, through the .src attribute of a script element created on the fly.  But the goal is to load some html markup with embedded script tags.

The markup describes an expanding table with the option to delete its own rows via another http get request, hence the need for the script.  It sounds convoluted, but works beautifully... in FF.
Link to comment
Share on other sites

sorry to be obtuse, but you'll have to spell it out for me.  eval() from where since the script tag isn't processed?

I could do it as an onload attribute of an img tag...  but I'm wondering what specifically you had in mind.

The page that is being loaded into a div via http get looks something like this:
[code]
<sc ript>
function row_del() {
  /* deletes a table row */
}
</sc ript>

<table><tr><td>...content...</td><td><a href="javascript:row_del()>delete</a></td></tr></table>
[/code]

IE doesn't seem to retain anything in the script tag.
Link to comment
Share on other sites

So search the response string for an embedded script tag, and eval() the contents, and do this in the process reply function - allowing the script to be retained in the block where it is most logical.  But probably I need to use a tag other than the script tag, or in Firefox the script will get evaluated twice.  Something like:
[code]<!--<evalscript>/* do scripty stuff */</evalscript>-->[/code]

Thoughts?

-pnj
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.