pkdevbox / iui

Automatically exported from code.google.com/p/iui
MIT License
0 stars 0 forks source link

Fragments return via AJAX do not have their <script> tags executed #102

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Return a fragment through ajax, have a script tag embedded 
2. since iui does an innerHTML replace, script tags are not eval'd
3.

What is the expected output? What do you see instead?
Script tags are evaled

What version of the product are you using? On what operating system?

Please provide any additional information below.
 I've attached a patch

Original issue reported on code.google.com by wayne...@gmail.com on 13 Aug 2008 at 11:30

Attachments:

GoogleCodeExporter commented 9 years ago
I've put this in, but is see strange behavior and I found an alternate method.  
when
I go back the link I clicked is highlighted and the loading spinner is spinning.

Original comment by austin.f...@gmail.com on 21 Nov 2008 at 7:28

GoogleCodeExporter commented 9 years ago
hi,
i added this js code in iui.js, it's not working, i want to integrate AdMob 
iPhone
ads  on my iphone sites.
thanks

Original comment by drsee...@gmail.com on 15 Jan 2009 at 5:01

GoogleCodeExporter commented 9 years ago
Hello,
I've independently  discovered the same issue yesterday, and I've fixed that in 
a
slightly different way.
I've found this post, which explains the problem and gives a nice hack, based 
on jquery:
http://www.vulgarisoip.com/2007/06/22/execute-javascript-injected-using-innerhtm
l-attribute-even-with-safari/

I've simply translated it into plain javascript code:

var elements = document.getElementsByClassName('javascript');
for (var element in elements) { 
  eval(elements[element].innerHTML);
}

and I've pasted it at line 87 of iui.js version 0.20-beta1.
I'm attaching the modified version.

With this fix, you have to put javascript code into div tags. For example:

<div class="javascript">alert("Hello World!");</div>

This let you test your webapps in firefox.

Original comment by ser...@gmail.com on 2 May 2009 at 5:51

Attachments:

GoogleCodeExporter commented 9 years ago
I've added a line o my previous comment code.
With this new version the javascript divs are removed after their evaluation, in
order to avoid multiple execution of javascript from all the page fragments.

var elements = document.getElementsByClassName('javascript');
for (var element in elements) { 
  eval(elements[element].innerHTML);
  elements[element].parentNode.removeChild(elements[element]);
}

Original comment by ser...@gmail.com on 8 May 2009 at 1:43

GoogleCodeExporter commented 9 years ago
That was the easiest trick of all to get Javascript going! Thansk a ton!

Original comment by kbco...@gmail.com on 5 Jun 2009 at 1:54

GoogleCodeExporter commented 9 years ago
Hi, 

I'm running into this issue, too - both on Quicktime poster frames that link to 
a
video (won't work unless it's in the main file - not if ajaxed to an external 
page),
and on this following script that embeds a Feedburner feed into the page:

<script src="http://feeds.feedburner.com/Waanzee?format=sigpro&nItems=1"
type="text/javascript" ></script>

How would I need to rephrase that script to work with this proposed hack?

Original comment by raamw...@gmail.com on 5 Aug 2009 at 12:06

GoogleCodeExporter commented 9 years ago
man thanks!!! exactly what i need to be able to show a map on my app without a 
lot of
work!

Original comment by senna...@yahoo.com on 18 Aug 2009 at 6:25

GoogleCodeExporter commented 9 years ago
its on the roadmap for 0.4

Original comment by melcher....@gmail.com on 18 Aug 2009 at 7:13

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I like this technique, but it seems to me it would be nicer to hunt for 
<script> tags
instead of <div class="javascript>.  That way it feels like what I'm emitting is
"proper" HTML.

I suppose the objection is that some browsers already run <script> tags, so the
proposed technique "hides" the script in a div to prevent that - this way we 
know the
script will only be evaled here, and not by the browser.  I guess I'd prefer 
that
this code only execute on browsers that don't do the script evaluation on 
innerHTML
insertion.  Or some other trick to get a single evaluation.

Original comment by janno...@gmail.com on 2 Oct 2009 at 2:24

GoogleCodeExporter commented 9 years ago
The hooks are in iui-0.40-dev1 - anyone care to update this patch or one of the 
similar ones to work with these 
events, see: http://code.google.com/p/iui/wiki/FormsAndExtensibility and the 
code itself.

Original comment by msgilli...@gmail.com on 7 Oct 2009 at 7:42

GoogleCodeExporter commented 9 years ago
I've created an extension in the "sandbox" that is inspired by this patch and 
also includes functionality from the 
patch for Issue #128.  It uses the "events" feature of iUI 0.40.

Original comment by msgilli...@gmail.com on 10 Feb 2010 at 11:29

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Issue 83 has been merged into this issue.

Original comment by msgilli...@gmail.com on 4 May 2010 at 5:10

GoogleCodeExporter commented 9 years ago
Has this patch been put in Release 0.40 Development Test Release 2? Other than 
adding <div class="script"></div> in my code, do I need to make other changes?

I downed 0.40 and checked the iui.js and didn't find the code sersim mentioned.

I'm new to iui project and appreciate your help.

Original comment by scott.zy...@gmail.com on 1 Jun 2010 at 5:51

GoogleCodeExporter commented 9 years ago
Scott, you'll have to use Mercurial to check it out.   Google provides 
instructions in the "Code" tab.  A "dev3" 
release is coming soon - then you'll be able to download a zip.

Original comment by msgilli...@gmail.com on 3 Jun 2010 at 7:42

GoogleCodeExporter commented 9 years ago
Hmm, I don't see sersim's hack working at all. Instead it prints whatever's 
between <div class="javascript"> </div> tags to the screen, not executing the 
code. 

Something I've missed?

Original comment by rjensenk...@gmail.com on 2 Jan 2011 at 12:32

GoogleCodeExporter commented 9 years ago
Do we have a fix for this problem in the latest version?

Thank you.

Original comment by angra...@gmail.com on 23 Aug 2011 at 8:47