Welcome to WebmasterWorld Guest from 54.227.1.130

Forum Moderators: travelin cat

Message Too Old, No Replies

Safari / javascript fix (oh please, oh please)

Javascript works in all browsers but Safari (possible document.all problem?

     

deifert

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

5+ Year Member



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

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

WebmasterWorld Senior Member whoisgregg is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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

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

WebmasterWorld Senior Member 10+ Year Member



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

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

WebmasterWorld Senior Member whoisgregg is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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

deifert

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

5+ Year Member



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

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

WebmasterWorld Senior Member whoisgregg is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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

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

5+ Year Member



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

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

WebmasterWorld Senior Member whoisgregg is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Happy to help. :)
 

Featured Threads

Hot Threads This Week

Hot Threads This Month