Reputation: 778
I'm trying to demonstrate the consequences of an XSS flaw to a client and to do so I need to retrieve a page, change some of the html in it with a simple search and replace, before finally displaying the data in an iframe. I have figured out the first two parts, but I'm struggling getting the iframe to work.
Here's what I have so far:
<html>
<head>
<script type="text/javascript">
function getSource()
{
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
var content=xmlhttp.responseText;
document.write(content.replace(/MyString/gi, "StringtoReplace"));
}
}
xmlhttp.open("GET","indextest.html",true);
xmlhttp.send();
</script>
</head>
<body>
<body onload="getSource()">
</body>
</html>
How then would I put this into an iframe? I've been trying to put the document.write line into a variable and calling that as the iframe src but having no luck so far. Any suggestions? Thanks a lot
Upvotes: 1
Views: 5927
Reputation: 1311
Instead of writing by using document.write(), use this:
var iframe = document.getElementById("YOUR IFRAME ID HERE");
iframe.contentDocument.write("HTML TAGS AND OTHER STUFF HERE");
Upvotes: 1