I’ve been trying to show a graph inside a WordPress Template. It works fine with this format:
JavaScript
x
3
1
<iframe height="500" src="https://datasource.com/fantom/0xf704f5ac5edf152168e07e6f5f108366911250ac?embed=1&theme=dark&trades=0&info=0">
2
</iframe>
3
But I can’t seem to make it work in a template using dynamic metadata.
JavaScript
1
15
15
1
<script>
2
function ShowGraph() {
3
var RawNetwork=document.getElementById("TokenNetwork").innerHTML;
4
var Network = RawNetwork.replace(/<[^>]*>/g, '');
5
6
var RawAddress=document.getElementById("TokenAddress").innerHTML;
7
var Address = RawAddress.replace(/<[^>]*>/g, '');
8
9
const Graph = 'https://datasource.com/' + Network + '/' + Address + '?embed=1&theme=dark&trades=0&info=0';
10
document.getElementById('TokenGraph').src = Graph;
11
}
12
</script>
13
14
<iframe height="500" id="TokenGraph" src="" onLoad="ShowGraph();"></iframe>
15
I hope somebody can help me figure out what I’m missing here.
Cheers mates!
Advertisement
Answer
There is a loop. Onload you are changing the src and then onload fires again.
try
JavaScript
1
14
14
1
<script>
2
window.onload = function () {
3
var RawNetwork=document.getElementById("TokenNetwork").innerHTML;
4
var Network = RawNetwork.replace(/<[^>]*>/g, '');
5
6
var RawAddress=document.getElementById("TokenAddress").innerHTML;
7
var Address = RawAddress.replace(/<[^>]*>/g, '');
8
9
const Graph = 'https://datasource.com/' + Network + '/' + Address + '?embed=1&theme=dark&trades=0&info=0';
10
document.getElementById('TokenGraph').src = Graph;
11
}
12
</script>
13
<iframe height="500" id="TokenGraph" src=""></iframe>
14