homepage Welcome to WebmasterWorld Guest from 23.20.220.79
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / WebmasterWorld / The Macintosh Webmaster
Forum Library, Charter, Moderators: travelin cat

The Macintosh Webmaster Forum

    
Safari / javascript fix (oh please, oh please)
Javascript works in all browsers but Safari (possible document.all problem?
deifert




msg:3299189
 3:46 pm on Apr 1, 2007 (gmt 0)

Hi Folks --

I'm working on a very simple javascript "Orders" page for a photographer friend of mine. He wants potential customers to see a small thumbnail of the desired print whenever they select a matching title from a dropdown list. I've coded a sample page using tables and an <iframe> that works in all browsers (PC and Linux, including Konqueror) but breaks in Safari. My tester (I don't own a Mac) reports that she can see the initial "Select Image" graphic in the <iframe>, but it doesn't change when choosing a new title from the list. The complete "Orders" test page is here:

<snip>

and the "stripped" version that has only the orders / thumbnail code is here:

<snip>

I had read elsewhere on the web that Safari has problems with any type of "document.all" code, which this page uses, but if I change the initial function:

function ShowWebSite(val)
{
document.all.myFrame.src=val;
}

to something like

function ShowWebSite(val)
{
val=document.getElementByID("myFrame").src
}

everything breaks -- the code no longer works in any browser. Can anyone here give me a clue to what I'm doing wrong?

Thanks in advance.

-- Darrell

[edited by: engine at 2:42 pm (utc) on April 2, 2007]
[edit reason] No urls, thanks. See TOS [webmasterworld.com] [/edit]

 

whoisgregg




msg:3300041
 2:19 pm on Apr 2, 2007 (gmt 0)

Welcome to WebmasterWorld [webmasterworld.com], deifert!

I don't know for sure what is broken with your code. However, it does matter what side of the equal sign your different values are on. If val is on the right side of the equal sign in the working code, I would expect to see it on the right side of the equal sign on the changed code. So in your broken code, you are setting the val variable to equal the current value of the iframe's src rather than setting the iframe's src to the current value of val.

Also, the code you posted is missing a semicolon (although that's probably just a copy and paste error).

Try:
function ShowWebSite(val)
{
document.getElementByID("myFrame").src = val;
}

timster




msg:3300265
 5:12 pm on Apr 2, 2007 (gmt 0)

missing a semicolon

That shouldn't matter (at the end of a line). JavaScript considers line endings to be statement terminators.

[safari.oreilly.com ]

whoisgregg




msg:3300319
 6:19 pm on Apr 2, 2007 (gmt 0)

Good catch timster. I'm in PHP mode right now where a missing semicolon spells automatic death. :)

deifert




msg:3300642
 12:39 am on Apr 3, 2007 (gmt 0)

Thanks for checking - I substituted the following code:

function ShowWebSite(val)
{
document.getElementByID("myFrame").src = val;
}

for the "document.all" line, but it broke in all my PC browsers, so I'm assuming it won't work in Safari either.

<frustration> If Apple is really concerned that we develop for Safari, do they maintain any kind of "official" help line to iron out these kinds of problems? </frustration>

Again, tx for the help.

-- Darrell

whoisgregg




msg:3300972
 1:27 pm on Apr 3, 2007 (gmt 0)

We don't need to start blaming anyone to solve this problem. :)

Function names in Javascript are case-sensitive. getElementByID should be getElementById.

I make the same mistake constantly. Heck, I even copied and reposted the mistake in my last post. :/

deifert




msg:3301598
 12:24 am on Apr 4, 2007 (gmt 0)

Son of a ..... <ahem>. Yup, that did it. Works so far in Firefox and IE. I'll email my Safari tester tomorrow and give it a whirl (fingers crossed). Many, MANY thanks for your help.

-- Darrell

whoisgregg




msg:3302048
 1:41 pm on Apr 4, 2007 (gmt 0)

Happy to help. :)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / WebmasterWorld / The Macintosh Webmaster
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved