Skip to main content

javascript onclick combining 2 events does not work on ios (iPhone, iPad)



I'm combining 2 javascripts in the onclick to do 2 things:








1. Stop an audio player


2. Load and iframe that has a video





The following code works on all browsers but not iOS (iPhone, iPad)







<a class="aboutclick" href="#" onclick="stop2();document.getElementById('frame').innerHTML='&lt;iframe src=&quot;paul-on-paul.html&quot; width=&quot;100%&quot; height=&quot;600&quot; scrolling=&quot;no&quot; frameborder=&quot;no&quot;&gt;&lt;/iframe&gt;'"><img src="assets/video-cold.jpg" alt="paul-gregory-video" width="161" height="81" border="0" /></a>







The stop2() in the beginning of the onclick code is what turns off the music player. (it's Flash audio player so it doesn't apply to iOS). Tapping on the image does nothing on the iPad, iPhone with this code present.





If I remove stop2(); from the onclick code the iframe will load on iOS devices.





I need to be able to use the stop2() to kill the music but I also need it to work on the iOS devices.





Any suggestions?





Working example: http://www.fixxed.com/test/pg (click on the video thumbnail at lower right)


Comments

  1. First I would suggest you move your move all your onclick code into a function and then call that function on click, like this:

    window.foo = function(e) {
    stop2();
    document.getElementById('frame').innerHTML='<iframe src="paul-on-paul.html" width="100%" height="600%" scrolling="no" frameborder="no"></iframe>'
    }

    ...

    <a class="aboutclick" href="#" onclick="foo">
    <img src="assets/video-cold.jpg" alt="paul-gregory-video" width="161" height="81" border="0" />
    </a>


    That just makes things much nicer to read and more maintainable. Then I would suggest that you look into using mobile touch events instead of click events, you will end up with something like this:

    window.foo = function(e) {
    stop2();
    }

    window.bar = function(e) {
    document.getElementById('frame').innerHTML='<iframe src="paul-on-paul.html" width="100%" height="600%" scrolling="no" frameborder="no"></iframe>';
    }

    ...

    <a class="aboutclick" href="#" onclick="foo" ontouchstart='bar'>
    <img src="assets/video-cold.jpg" alt="paul-gregory-video" width="161" height="81" border="0" />
    </a>

    ReplyDelete
  2. It seems like iOS is choking on your stop2() call. You might want to try detecting if the browser is an iOS device (one simple and not-so-good way of doing that might be with the user-agent string) or (better) check to see if the browser supports that functionality using Modernizr. Then, if you detect that it's an iOS browser, just return from stop2().

    Hope this helps!

    ReplyDelete

Post a Comment

Popular posts from this blog

Slow Android emulator

I have a 2.67 GHz Celeron processor, 1.21 GB of RAM on a x86 Windows XP Professional machine. My understanding is that the Android emulator should start fairly quickly on such a machine, but for me it does not. I have followed all instructions in setting up the IDE, SDKs, JDKs and such and have had some success in staring the emulator quickly but is very particulary. How can I, if possible, fix this problem?

CCNA 3 Final Exam => latest version

1 . Which security protocol or measure would provide the greatest protection for a wireless LAN? WPA2 cloaking SSIDs shared WEP key MAC address filtering   2 . Refer to the exhibit. All trunk links are operational and all VLANs are allowed on all trunk links. An ARP request is sent by computer 5. Which device or devices will receive this message? only computer 4 computer 3 and RTR-A computer 4 and RTR-A computer 1, computer 2, computer 4, and RTR-A computer 1, computer 2, computer 3, computer 4, and RTR-A all of the computers and the router   3 . Refer to the exhibit. Hosts A and B, connected to hub HB1, attempt to transmit a frame at the same time but a collision occurs. Which hosts will receive the collision jamming signal? only hosts A and B only hosts A, B, and C only hosts A, B, C, and D only hosts A, B, C, and E   4 . Refer to the exhibit. Router RA receives a packet with a source address of 192.168.1.65 and a destination address of 192.168.1.161...