I'll try to work through this from the end to the beginning George. 1.) Yes the escapes for the quotations are because I cut the code out of our PHP generator. If you are typing the code directly into the HTML they are not needed - indeed wrong.
2.) The <CODE> tags are simply for pasting into bulletin boards such as this Google group to prevent the BB software altering the source code. The <CODE> doesn't belong in the application itself. 3.) As for the part that installs the EventListener I don't quite follow the problem. I cut your code out of your reply and pasted it straight into our application and it gave no error, and in fact ran our embedded scripts OK. I see no missing braces or extra ; Perhaps you could post the entire myproject.js script if it is not too long and I will try running it verbatim. What browser are you running this on - iPhone Safari? On Dec 4, 6:51 pm, Bontas George <[email protected]> wrote: > Hi Skip, > > Good idea, but I am not so pro with javascript and general web applications > (first project). So when I put your code in the .js file I was surprised to > see that there are errors. First one is here > (function () { > addEventListener("load", function(event) > { > document.body.addEventListener('beforeinsert', beforeFragmentInsert, > false); > > }, false); //at this line and says that a bracket } is needed. everything > good because I deleted the ; and error wasn't there anymore! > })(); > > Ok now the error is at this line: var f = event['fragment']; ----- and this > is not normal because it is correct!!! what I've seen is that if I remove the > <CODE> tags everything is working nicely... I really would like to know what > is the issue!! > > And something else too in the HTML: > why so: <script type=\"application/javascript\" src=\"myproject.js\"></script> > and not so: <script type="application/javascript" src="myproject.js"></script> > because the first one is killing the tags in my source... I think so... > > If you have the time to give me short points to this or what to look for > cause I googled a little bit but I'm not on the correct path! > > Thanks, > George > > ________________________________ > From: skip <[email protected]> > To: iPhoneWebDev <[email protected]> > Sent: Thu, December 3, 2009 11:11:16 PM > Subject: Re: javascript execution > > If you want JavaScript code to execute when fragments are loaded into > a framework such as iUI here is how we do it. > > First, make sure you are using the "latest" (at least v 0.40-dev1) > version of iUI which has dispatchEvent hooks built into it. > > Next create a little javascript file for your custom use in your > project (say it is myproject.js). > > Here is an extracted snippet from our custom project file which > contains just the code required to do the "script execution" > > <CODE> /* This would be your myproject.js */ > > /* Special scripts for the Mediweb iPhone project > * wrh Nov 2009 - SVMHS > * St. Vincents and Mater Health Sydney > */ > > (function () { > addEventListener("load", function(event) > { > document.body.addEventListener('beforeinsert', beforeFragmentInsert, > false);}, false); > })(); // End of the self-executing function that loads the event > > handlers > > //This is the event handler for "beforeinsert" event in iUI > function beforeFragmentInsert(event) { > > // if we find any inline scripts - execute them > var f = event['fragment']; > if (f.tagName.toLowerCase() == "script") // check the root of the > fragment > eval(f.innerHTML); > > var n = f.getElementsByTagName("script"); // and any elements below > the root > for (z=0; n && z<n.length;z++) > { > eval(n[z].innerHTML); > f.removeChild(n[z]); // prevent the script from flashing on > the screen > } > > } > > /* This would be the end of the myproject.js snippet */</CODE> > > Now in the <head> element of the first HTML page of your iUI project > add the following line as the last js declaration: > > <script type=\"application/javascript\" src=\"myproject.js\"></script> > > Now you will find that any <script> elements contained in the fragment > will execute after your fragment has been downloaded by Ajax and > before it is actually inserted into the displayable document. If you > want it after the insert into the document there would be a couple of > small changes required. > > Good luck, > Skip > > /* Special scripts for the Mediweb iPhone project > * wrh Nov 2009 - SVMHS > * St. Vincents and Mater Health Sydney > */ > > (function () { > addEventListener("load", function(event) > { > document.body.addEventListener('beforeinsert', beforeFragmentInsert, > false);}, false); > })(); // End of the self-executing function that loads the event > > handlers > > //This is the event handler for "beforeinsert" event in iUI > function beforeFragmentInsert(event) { > > // if we find any inline scripts - execute them > var f = event['fragment']; > if (f.tagName.toLowerCase() == "script") // check the root of the > fragment > eval(f.innerHTML); > > var n = f.getElementsByTagName("script"); // and any elements below > the root > for (z=0; n && z<n.length;z++) > { > eval(n[z].innerHTML); > f.removeChild(n[z]); // prevent the script from flashing on > the screen > } > > On Dec 4, 1:14 am, Bontas George <[email protected]> wrote: > > > > > Sorry skip!!! I has not attentive and did not knew about this issue!! I'll > > be more attentive regarding hijacking!!! :p > > > But if you can help I badly need it!!! this fragments are really killing me > > slowly. > > > 10x and sorry again, > > > George > > > ________________________________ > > From: skip <[email protected]> > > To: iPhoneWebDev <[email protected]> > > Sent: Thu, December 3, 2009 11:28:36 AM > > Subject: Re: javascript execution > > > This thread was initially about iPhone screen resizing during drop > > down selects. You have hijacked the thread to discuss execution of > > Javascript in fragments, and also changed the title of the thread. At > > the very least this is unhelpful. If you promise not to hijack > > anymore discussion threads I will tell you how to make javascripts > > execute when fragments are loaded - we do it all the time. > > > You haven't helped me to solve my problem at all. > > > Skip > > > On Dec 3, 1:01 am, Bontas George <[email protected]> wrote: > > > > Hello everybody, > > > > I have another question that keeps me busy!!! I need on loading of some > > > pages to run a javascript! how can this be done! > > > example: the javascript is not executed!!! :(( > > > <div id="graph" title="Graph" > > > > <fieldset> > > > <div class="row"> > > > > <table style="width:290px;height:20px; background-color:#FFF"> > > > <tr> > > > <td align="center" bgcolor="#2d3642" > > > style="color:#FFF">50 min</td> > > > <td align="center" bgcolor="#2d3642" > > > style="color:#FFF">75 min</td> > > > <td align="center" bgcolor="#2d3642" > > > style="color:#FFF">100 min</td> > > > </tr> > > > </table> > > > > <div id="placeholder" style="width:290px;height:150px; > > > background-color:#000"></div> > > > > </div> > > > <div class="row"> > > > <p> > > > <div class="whiteButton" onclick="graph()">View graph</div> > > > </p> > > > </div> > > > </fieldset> > > > </div> > > > > <script type="text/javascript"> > > > $(document).ready(function(){ > > > var d1 = []; > > > for (var i = 0; i < 14; i += 0.5) > > > d1.push([i, Math.sin(i)]); > > > > var d2 = [[0, 3], [4, 8], [8, 5], [9, 13]]; > > > > // a null signifies separate line segments > > > var d3 = [[0, 12], [7, 12], null, [7, 2.5], [12, 2.5]]; > > > > $.plot($("#placeholder"), [ d1, d2, d3 ]); > > > > }); > > > -- > > > You received this message because you are subscribed to the Google Groups > > "iPhoneWebDev" group. > > To post to this group, send email to [email protected]. > > To unsubscribe from this group, send email to > > [email protected]. > > For more options, visit this group > > athttp://groups.google.com/group/iphonewebdev?hl=en. > > -- > > You received this message because you are subscribed to the Google Groups > "iPhoneWebDev" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group > athttp://groups.google.com/group/iphonewebdev?hl=en. -- You received this message because you are subscribed to the Google Groups "iPhoneWebDev" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/iphonewebdev?hl=en.
