I try to add an button via Tampermonkey to websites. That button should only appear in the outer body and not in iframes.
So, for example, this is before the Tampermokey runs...
<html>
<head>...</head>
<body>
...
...
<iframe src="https://xyz.abc", id="myID">
<html>
<head>...</head>
<body>
...
...
</body>
</html>
</iframe>
</body>
</html
I try to add an button like this:
var zNode = document.createElement('div');
zNode.innerHTML = '<button id="myButton" type="button">' +
'submit</button>';
zNode.setAttribute('id', 'myContainer');
var first = document.getElementsByTagName('body')[0];
first.appendChild(zNode);
// add an event handler, etc...
But this piece of code is not ignoring the body tag in the iframe and my button appears in both body tags.
<html>
<head>...</head>
<body>
<div id="myContainer"><button id="myButton"
type="button">Clear Session</button></div>
...
<iframe src="https://xyz.abc", id="myID">
<html>
<head>...</head>
<body>
<div id="myContainer"><button id="myButton"
type="button">Clear Session</button></div>
...
</body>
</html>
</iframe>
</body>
</html
What I would like to archive is to add the button only in the outer body (not as part of the iFrame). Please notice, I cannot modify the webpage, I can only try to adapt my code by Tampermonkey... Are you able to support me here please? Thanks