I have code which works for every browser except IE (surprise, surprise).
This is tricky stuff though. We had a coldfusion custom tag which generates advertisement code in the body of the document. But, for page load speed reasons, we decided to try and load the code returned from the custom tag using jQuery after the document was ready.
We’ve tried nearly every possible method, each with its own hassles. Finally settled on calling the custom tag in a hidden div at the bottom of the page initially, then using jQuery to get the specific portion of the code we needed and loading it into its final resting place further up the page.
We have five ads altogether. One of them returns code that IE can’t work with. The rest all work fine.
The four OK ads return a hyperlink string from the custom tag (e.g. as follows), which is easy to work with and works in all browsers:
<a href="http://bs.serving-sys.com/BurstingPipe/adServer.bs?cn=brd&FlightID=2997227&Page=&PluID=0&Pos=9088"
target="_blank">
<img src="http://bs.serving-sys.com/BurstingPipe/adServer.bs?cn=bsr&FlightID=2997227&Page=&PluID=0&Pos=9088"
border="0"
width="300"
height="250">
</a>
We use the following code to load into temp div (divx), then extract and reload into final position (left2):
$('#divx').html("").load('/remoteAd.cfm?type=left2&referrer=/index.cfm',
function(g){
var xx = $('#divx').html());
$('#left2').html(xx);
});
HOWEVER, the troublesome one returned a huge block of code that broke javascript when we tried to assign it to a variable (I can’t even load it here without it breaking. You can view it in the source code of this page), so we decided to extract it using .text():
var xx = $('#divx').text();
instead of
var xx = $('#divx').html();
This extracts the following js STRING (complete with line breaks) in ALL BROWSERS EXCEPT IE:
ajaxinclude("/remoteAd.cfm?type=right1&referrer=/index.cfm");
function ebStdBanner1_DoFSCommand(command,args){
try{
command = command.replace(/FSCommand:/ig,"");
if((command.toLowerCase() == "ebinteraction") ||
(command.toLowerCase()=="ebclickthrough"))
gEbStdBanners[1].handleInteraction(args);
else if(command.toLowerCase()=="ebversiontrackingimpression")
gEbStdBanners[1].ebversiontrackingimpression(args);
} catch(e) {}
}
function ebIsFlashExtInterfaceExist(){
return true;
}
<a href="http://bs.sys.com/adServer.bs?cn=brd&FlightID=2997227&Page=&PluID=0&Pos=9088"
target="_blank">
<img src="http://bs.serving-sys.com/BurstingPipe/adServer.bs?cn=bsr&FlightID=2997227&Page=&PluID=0&Pos=9088"
border=0
width=300
height=250>
</a>
It’s a simple matter to extract the hyperlink block from the string, thanks to suggestions from others on stackoverflow.
HOWEVER, in IE9, I get a blank result for alert($('#divx').text());
Can anyone tell me WHY?. It’s ruining my day.
You can view the code that loads into the temp div by viewing the source code of this page. All I want to do is access this as text() and isolate the <a>...</a> block from it before loading that into its final div.
What browser/document mode are you in? I think I get correct data in Browser Mode: IE9 and Document Mode: IE9 standards. Switching document mode to anything other than IE9 standards returns empty .text() data.
Including the additional information regarding this for future visitors:
Here’s additional info:
http://blogs.msdn.com/b/ie/archive/2010/10/19/testing-sites-with-browser-mode-vs-doc-mode.aspx
and to force IE9 into standards mode: http://msdn.microsoft.com/en-us/library/cc288325(VS.85).aspx