homepage Welcome to WebmasterWorld Guest from 54.205.205.47
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe and Support WebmasterWorld
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
How to get a JS script to work in all browsers
javascript and browsers
steveoh




msg:4597675
 2:37 pm on Jul 30, 2013 (gmt 0)

I copied a script from a site that made bats fly around the page. It only appeared to work on IE, but with trial and error found it would work on any browser if there was no doc-type declaration, and just <html> at the top of the page. Any ideas about a workaround so that it would work on all browsers, but with a valid doc-type?

 

DrDoc




msg:4597695
 3:51 pm on Jul 30, 2013 (gmt 0)

Welcome to WebmasterWorld, steveoh!

Seems like this was asked recently? A brief sample of code would probably be helpful.

The short answer is -- the JavaScript you copied was (likely) poorly written. Getting something to work in all browsers isn't rocket science. It's simply lack of laziness.

Kudos for desiring a valid doctype. Again, a brief code sample would help.

Dijkgraaf




msg:4597899
 2:37 am on Jul 31, 2013 (gmt 0)

How about just trying the HTML5 standard?
<!doctype html>
<html lang="en">

Setting the language as desired of course

lucy24




msg:4597904
 2:53 am on Jul 31, 2013 (gmt 0)

with trial and error found it would work on any browser if there was no doc-type declaration

In other words: the code as written works only in "quirks" mode, so there is something non-compliant about it-- or, more likely, in the HTML it generates. Browsers will generally recognize HTML 5 features even if the dtd says HTML 4, so that shouldn't be the problem.

You'll need to fine-tooth-comb the code. Break it down into small bits, or comment-out most of it. You'll find some particular point where it stops working as intended. Once you've isolated the issue, you can work on fixing it. And you'll end up with better code.

birdbrain




msg:4597932
 7:23 am on Jul 31, 2013 (gmt 0)

Hi there steveoh,

one possible reason for failure is the lack of specified values. ;)

For example something like this...


someObject.style.top=xPos;



...will need to be changed to...


someObject.style.top=xPos+'px';



birdbrain

steveoh




msg:4598049
 2:58 pm on Jul 31, 2013 (gmt 0)

Hi guys,

Thanks very much for getting back to me.

I did ask a similar question recently, and that script did work in most browsers, but it was the HTML that was producing errors in W3 validation. That's sorted now.

I tried using <!doctype html> but it didn't make a difference.

Going through the code with a fine tooth-comb won't be of much use as I know next to nothing about JavaScript.

It's seems a shame that there isn't a quick fix as I liked the effect and it did work in all browsers, but I'll leave it. I can't expect you to rewrite someone else's code.

Thanks again for your time.

birdbrain




msg:4598060
 3:05 pm on Jul 31, 2013 (gmt 0)

Hi there steveoh,

post the script, and we will get it to work. ;)

birdbrain

steveoh




msg:4600309
 3:10 pm on Aug 8, 2013 (gmt 0)

Thanks for the invite.
I've put up the code that generates the HTML, as it was suggested that that may be causing the problems (I've changed some from upper to lower case but it didn't seem to improve it).

var ns6=document.getElementById&&!document.all
bats=new Array(3)
if (document.layers){
for (i=0; i < amount; i++)
{document.write("<layer name=n"+i+" left=0 top=-50><img src='"+Cupid.src+"' name='nsi' width='69' height='60' border='0'></layer>")}
}
else if (document.all||ns6){
document.write('<div id="out" style="position:absolute;top:0;left:0"><div id="in" style="position:relative">');
for (i=0; i < amount; i++){
if (document.all)
document.write('<img src="'+Cupid.src+'" id="msieBats" style="position:absolute;top:-50;left:0" border=0>')
else
document.write('<img src="'+Cupid.src+'" id="ns6Bats'+i+'" width=69 height=60 style="position:absolute;top:-50;left:0" border=0>')
}
document.write('</div></div>');
}

Fotiman




msg:4600314
 3:29 pm on Aug 8, 2013 (gmt 0)

Anything that's looking for Netscape 6 is a sure sign of a script you should probably not use. It's using layer elements (non-standard junk) and document.write (which should be avoided). I'd find a new script. :/

The script that you posted does not seem to be complete, however.

DrDoc




msg:4600316
 3:36 pm on Aug 8, 2013 (gmt 0)

Yikes, that's an old script!

That said --
top:-50 -- the unit is missing here. 50 what? Pixels? Ems? Inches? ;)
steveoh




msg:4600317
 3:38 pm on Aug 8, 2013 (gmt 0)

Thanks very much for this,
I didn't want to put up the whole script as it's quite lengthy

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved