问题
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