0

I have a problem getting an svg file and javascript file talking. They are both referred to in this html document - http://www.trjps.co.uk/image_store_old/button_tests/button_tester_A.html. I want a button click on an svg element (the small circle) to trigger a js function (an animation using rapael).

I got something like this to work on a small demo

  <path onclick="setAttribute('style','fill:gold'), top.popup()"... />

but it won’t work on this more complex one.

I know many answers cover this topic but, still, I’ve had no success. Help and pointers are welcome and needed. I might be barking up the wrong tree on how I'm doing this. Thank

GMcG
  • 33
  • 2
  • Just a guess, but did you try using an iframe instead of an object tag? Do you get the problem if you include the SVG directly in the containing HTML file? – Brett Zamir Sep 24 '12 at 23:57
  • I hadn't tried these specifically but I just did and sadly neither changed matters. Both work like the original though. – GMcG Sep 25 '12 at 00:33
  • 1
    Can you set up a jsfiddle.net? – Neil Sep 25 '12 at 08:30
  • similar to http://stackoverflow.com/questions/10485232/how-to-call-a-function-in-the-parent-html-document-from-an-embedded-svg – Erik Dahlström Sep 25 '12 at 09:02
  • I got it going! Oddly 'window.onload = function() {...}' was stopping everything. My whole javascript was encased in this function, as the raphael examples suggested. I took it out and got results. I've not done much js and have no idea why this matters but it does. Maybe I'll learn it's importance in due course but for the time being, "done it better than perfect" as a sizable social media company may or may not have printed on it's walls. Thanks for the helps. – GMcG Sep 26 '12 at 03:19
  • please post your solution as an answer, so others tackling the same issue may benefit from it. – Eliran Malka Sep 29 '12 at 09:51

1 Answers1

0

I got it working. This was stopping it

window.onload = function() {..(all my raphael javescript)..}

My whole javascript was encased in this function, as the raphael examples suggested. I took it out and got results.

I've not done much js and have no idea why this matters but it does. Maybe I'll learn it's importance in due course but for the time being, "done it better than perfect" as a sizable social media company may or may not have printed on it's walls. Thanks for the helps.

GMcG
  • 33
  • 2