Link to home
Create AccountLog in
Avatar of ddantes
ddantesFlag for United States of America

asked on

Conditional statement question

I have a scrolling image which needs to be smaller for iPhone.  Here is the code:
<ul id=scroller>
if ((navigator.userAgent.indexOf('iPhone') != -1)) {
document.write('<li><img src="images/1.jpg" Alt="" ></li>');
} else
{document.write('<li><img src="images/2.jpg" Alt="" ></li>');
}
</ul>

If I insert <script type="text/javascript"> above the opening <ul> tag, and </script> before the closing </ul>, then the image doesn't scroll.  If I insert it after the opening <ul> tag, I get an error that <ul> cannot contain a script tag.  If I leave it out, the page scrolls, but the same image is loaded, regardless of the user agent.  Please advise.
ASKER CERTIFIED SOLUTION
Avatar of Frosty555
Frosty555
Flag of Canada image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of ddantes

ASKER

Thank you, that really helped.