简体   繁体   中英

JavaScript not working in Tizen Web Widget

I'm working on a Tizen Web Widget Application . My javaScript file resides in MyProject >> widget >> MyProject >> js >> main.js . Even if I change the text of an element in the window.onload() method, it doesn't work.

I've also tried the accepted answer of this question but this also didn't work for me. Someone please guide me if there's any other check which I'm missing.

When writing a Web Widget, the most problems are caused by fact, that it has limited number of features supported. The example is not supported innerText and innerHTML , which you could used to change the content of html from javascript 'by default'.

To change the content of HTML element you need to use textContent instead. I tried to reproduce your problem this way:

index.html

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <link rel="stylesheet" type="text/css" href="css/style.css">
  <script src="js/main.js"></script>
  <style></style>
</head>

<body>
  <div id="page">
    <div id="container" onclick="changeContent()">
      <span id="content-text">Widget</span>
    </div>
  </div>
</body>
</html>
var changed = true;
window.onload = function() {
  console.log('[window.onload]');
  var box = document.getElementById("content-text");
  box.textContent = "starting content"
};

changeContent = function() {
    var box = document.getElementById("content-text");
    console.log('changeContent: ' + box.textContent)
    box.textContent = changed ? "abcdef" : "xyz";
    changed = !changed;
};

and code work well on Tizen emulator.

It is possible that you use feature, which is not supported. I suggest you checking carefully about features not supported in Web Widget and just not use them in your implementation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM