I am trying to make a link that tweets the dynamically dreated content of a number of divs all as one sentence
The Javascript
function toggle(){
var joe = document.getElementById("fulltxt");
document.getElementById("tweet").setAttribute('href','http://twitter.com/home?status=' +
joe.innerHTML)
}
The content i want to tweet
<div id="fulltxt">
<div id='action'> actiontext </div>
<div id='reason'> reasontext</div>
<div id="party"> partytext </div>
</div>
the link to tweet
<a id="tweet" href='#' onClick="toggle(this.value)">שתף בטוויטר</a>
The problem i am getting is
Invalid Unicode value in one or more parameters /intent/tweet?source=webclient&text=%3Cdiv+id%3D%22action%22%3E%F9%EC%E5%ED%3C%2Fdiv%3E%E5%E6%E4+%E1%E2%EC%EC%3Cdiv+id%3D%22party%22%3E%E1%E9%E1%E9+%F0%FA%F0%E9%E4%E5%3C%2Fdiv%3E
There could be two problems
- the html tags – so instead i would need string together the individual div’s (action + reason + party) instead of using fulltxt
- the language – (its its in hebrew) I think it may be an encoding issue
to test it, i replaced fulltxt in the function with the id of one of the individual divs and when the content of the individual div is in english it works but when its in hebrew it gives me an error
You are correct it is an encoding issue. Also innerHTML will include the tags of the nested divs.
IE supports innerText and the rest use textContent
encodeURIComponent