Declaring a div using Javascript not working in Safari

D

drew197

I am a newbie. This is someone else's code which I have to modify to
work in Mozilla and Safari. The changes I made so far have allowed it
to work in Mozilla but not Safari. It seems to be getting hung up on
the first line of code. I put an alert after that line and I never saw
it in Safari but I did see it in Mozilla. Any Thoughts?

Thanks,
Andrew

Here's the code:
{
document.write("<div id='orbitLayer' style='position:absolute;
left:0px; top:"+document.all['topBanner'].offsetWidth+"px;
width:"+document.all['topBanner'].offsetWidth+"px;
height:"+(document.body.offsetHeight-document.all['topBanner'].offsetHeight)+"px;
z-index:2'>");
document.write("<object
classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' ");
document.write("codebase='/flash/swflash.cab#version=4,0,2,0' ");
document.write("width='100%' ");
document.write("height='100%' ");
document.write("name='estee' ");
document.write("id='estee'>");
document.write("<param name=movie value='newmenu_pinkribbon.swf'>");
document.write("<param name=quality value=high>");
document.write("<param name='wmode' value='opaque'>");
document.write("<embed src='newmenu_pinkribbon.swf'");
document.write("quality=high
pluginspage='/flash/swflash.cab#version=4,0,2,0'");
document.write("type='application/x-shockwave-flash' ");
document.write("width='100%' ");
document.write("height='100%' ");
document.write("name='estee'");
document.write("id='estee'");
document.write("wmode='opaque' ");
document.write("swliveconnect='true'>");
document.write("</embed> ");
document.write("</object>");
document.write("</div>");
}
 
T

Tony

I am a newbie. This is someone else's code which I have to modify to
work in Mozilla and Safari. The changes I made so far have allowed it
to work in Mozilla but not Safari. It seems to be getting hung up on
the first line of code. I put an alert after that line and I never saw
it in Safari but I did see it in Mozilla. Any Thoughts?

No specific thoughts, but I have heard a few times that Safari suffers
from a less-than-adequate Javascript implementation. Add to that the
fact that a LOT of people tend to write code that only works on their
chosen browser (IE, quite often) and don't worry about cross-browser
compatibility.

If I were in your position, I would check the Safari Javascript
documentation and verify the details of the implementation of
document.write - Also, have you tested it with a simpler string? (say,
document.write('hello');?)
 
R

RobG

I am a newbie. This is someone else's code which I have to modify to
work in Mozilla and Safari. The changes I made so far have allowed it
to work in Mozilla but not Safari. It seems to be getting hung up on
the first line of code. I put an alert after that line and I never saw
it in Safari but I did see it in Mozilla. Any Thoughts?

Thanks,
Andrew

Here's the code:
{
document.write("<div id='orbitLayer' style='position:absolute;
left:0px; top:"+document.all['topBanner'].offsetWidth+"px;
width:"+document.all['topBanner'].offsetWidth+"px;
height:"+(document.body.offsetHeight-document.all['topBanner'].offsetHeight)+"px;

Safari does not support document.all. Mozilla (and other Gecko-based
browsers) provide 'undetectable' support for it in quirks mode. There
are suggestions on how to work with that in the FAQ:

<URL:http://www.jibbering.com/faq/#FAQ4_15>


You could do something like:

function getEl(id)
{
// Use getElementById if available - suits perhaps 90% of browsers
if (document.getElementById) return document.getElementById(id);

// Otherwise, use document.all if available - suits IE 4
if (document.all) return document.all[id];

// Otherwise return null - maybe 0.5% of browsers will end up here
return null;
}


Then in your code can be:

var tBanner = getEl('topBanner');
if (tBanner){
document.write( "..." + tBanner.offsetWidth + "...");
...
}


Multiple calls to document.write are inefficient, better to concatenate
the HTML as string, then use a single document.write, e.g.:


var tBanner = getEl('topBanner');
if (tBanner){
var htmlString = "<div id='orbitLayer' style='position:absolute;"
+ " left:0px; top:"
+ tBanner.offsetWidth
+ " px;z-index:2'><object"
+ " classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'"

// ...

+ "swliveconnect='true'>"
+ "<\/embed> "
+ "<\/object>"
+ "<\/div>";

document.write( htmlString );
}

[...]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top