![]() | |
![]() |
| | Thread Tools | Display Modes |
#21
| |||
| |||
|
|
quote You are obsessed! Just curious but when is it that you are wanting to do script insertion with totally random scripts you haven't written yourself or written by a coworker? Just academic interest? /quote For myself I am trying to write code that asynchronously injects adverts into a web page. You'll notice across the web millions of sites whose pages might be quite fast-loading in themselves, but with 3 or 4 massive delays as the page goes to ads.domain.com to fetch the ad code, which characteristically is a mix of javascript and html, and is generated by 3rd party software. |
|
I want this external data injected in the background, after the main page has finished rendering, for an improved user experience. Make sense? |
#22
| |||
| |||
|
|
I want this external data injected in the background, after the main page has finished rendering, for an improved user experience. Make sense? Put an IFrame on the page that has a secondary page in it that loads the ad. It will make your life simpler and save you a lot of sleepless nights. |
#23
| |||
| |||
|
|
In comp.lang.javascript message <1187625350.498917.232... (AT) i38g2000prf (DOT) go oglegroups.com>, Mon, 20 Aug 2007 15:55:50, Peter Michaux petermich... (AT) gmail (DOT) com> posted: If you are in control of writing the JavaScript bits then you can just write the JavaScript bits so there are no problems with using eval(). There is only one little complication and it is with naming global variables explicitly as global properties instead. Here is the pertinent part of the above page regarding this issue. Do you see any future problem in URL:http://www.merlyn.demon.co.uk/estrdate.htm#TT>? One enters code in the blue bit just above heading "Testing and Timing" (the textarea is preloaded with a function body, but Javascript does not know that on loading, so use DEFINE & UNDEFINE), and executes it (check the checkbox) in the next blue bit. It's OK in IE6, FF2, Opera9 (though FF has a visible layout flaw). |
#24
| |||
| |||
|
|
Randy Webb said the following on 8/20/2007 8:46 PM: I have revised that function to accommodate NN6.1/NN6.2Win and hopefully it will accommodate the innerHTML mac browsers (iCab and IE). If anyone could test it on a non-windows browser I would be grateful. |
|
Added was the innerHTML testing so that browsers that execute innerHTML scripts wouldn't execute them twice. var innerHTMLFailed=true; window.onload = checkIt; function checkIt(){ document.getElementById('myDiv').innerHTML = '<script type="text/javascript">var innerHTMLFailed = false;<\/script>'} function loadHTMLFragment(elemId, HTMLFragment) { if (document && document.getElementById && document.getElementById(elemId) && document.createElement && document.appendChild && document.getElementsByTagName && { var el = document.getElementById(elemId); el.innerHTML = " " + HTMLFragment; //The is a hack to cause IE to process the //script elements if the first node in the //HTMLFragment is a script element. if(innerHTMLFailed) { var d =el.getElementsByTagName('script'); var t = d.length; for (var x=0;x<t;x++) { var newScript = document.createElement('script'); newScript.type = "text/javascript"; newScript.text = d[x].text; el.appendChild(newScript); } for (var y=0;y<t;y++) { el.removeChild(el.getElementsByTagName("script")[y]); } } } } Next step is a test of the .text attribute since I know of browsers that do not support setting the .text property of a newScript element. |
#25
| |||
| |||
|
|
On Aug 22, 7:01 am, Randy Webb <HikksNotAtH... (AT) aol (DOT) com> wrote: I want this external data injected in the background, after the main page has finished rendering, for an improved user experience. Make sense? Put an IFrame on the page that has a secondary page in it that loads the ad. It will make your life simpler and save you a lot of sleepless nights. Agreed, use an iframe and save yourself from a "world of pain." |
#26
| |||
| |||
|
|
On Aug 20, 8:52 pm, Randy Webb <HikksNotAtH... (AT) aol (DOT) com> wrote: Randy Webb said the following on 8/20/2007 8:46 PM: I have revised that function to accommodate NN6.1/NN6.2Win and hopefully it will accommodate the innerHTML mac browsers (iCab and IE). If anyone could test it on a non-windows browser I would be grateful. Have you posted a test page? I'll click some buttons for you and send you the results. |
#27
| |||
| |||
|
#28
| |||
| |||
|
#29
| |||||
| |||||
|
|
Hi All, |
|
quote Agreed, use an iframe and save yourself from a "world of pain." /quote |
|
You are of course quite right that this is the technically easiest solution. However a reason for not using an <iframe> just occurred to me - advert tracking. |
|
A key feature of an ad reporting system is to tell you what ads are shown/clicked on under what urls, and if every ad is in fact being served via an iframe from the same adServer.php url, then your ad reports carry at lot less value - possibly to the point of ruining your business, if it depends on ad revenue. |
|
Now I think about it this might well be the reason most big sites do *not* load their ads via <iframes>. |
#30
| ||||
| ||||
|
|
After all this fuss about script insertion and getting scripts to execute in global scope, I found myself looking through the jQuery code. ------------------------ // Evalulates a script in a global context // Evaluates Async. in Safari 2 :-( globalEval: function( data ) { data = jQuery.trim( data ); |
|
if ( data ) { if ( window.execScript ) window.execScript( data ); else if ( jQuery.browser.safari ) // safari doesn't provide a synchronous global eval window.setTimeout( data, 0 ); else eval.call( window, data ); |
|
} }, ------------------------ That window.setTimeout(data, 0) call seems like an easy solution to the scope problem. |
|
I may have missed it but was this every suggested here instead of all this script element insertion? |
![]() |
| Thread Tools | |
| Display Modes | |
| |