JavaScript not working in Tizen Web Widget

ε祈祈猫儿з 提交于 2020-03-25 13:42:26

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/60140013/javascript-not-working-in-tizen-web-widget

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!