1

I have this html code with external function call and local variables:

document.getElementById("data").innerHTML='<a href="#" onClick="cordova.exec("ChildBrowserCommand.showWebPage", "'+vivijesolo+'");"><img src="'+vivifoto+'" on;></a>';

The problem is that, it see's the variables and everthing is fine but the function cordova.exec can't be executable.

Why?? :(

  • 3
    The `"` is breaking the `onClick` attribute. it will only see `onClick="cordova.exec("` and then stop because the quote ends it – Esailija Jul 23 '12 at 13:23
  • var func='cordova.exec("ChildBrowserCommand.showWebPage", "'+vivijesolo+'");'; document.getElementById("data").innerHTML=''; try this, if it works, you need to change the way you use quotes. – CosminO Jul 23 '12 at 13:28
  • violation of [soc](http://en.wikipedia.org/wiki/Separation_of_concerns#HTML.2C_CSS.2C_and_JavaScript) – jbabey Jul 23 '12 at 13:29

3 Answers3

2

The " is breaking the onClick attribute. it will only see onClick="cordova.exec(" and then stop because the quote ends it

Try this

var elem = document.getElementById("data");
elem.innerHTML = '<a href="#"><img src="'+vivifoto+'"></a>';

elem.firstChild.onclick = function() {
    cordova.exec( "ChildBrowserCommand.showWebPage", vivijesolo );
};
Esailija
  • 138,174
  • 23
  • 272
  • 326
  • one question, how can i push var elem. items.push('
  • ' + val + '
  • '); i've tried but i always get an error [objectHTMLDivElement] –  Jul 24 '12 at 08:52
  • @BojanVidanovic can you make a new question with full code? I really need more context for that – Esailija Jul 24 '12 at 08:54