I have the following code to save the contents of the DOM to a file. I am getting problem when I am using this with 'm.amazon.com' website. I can see image is getting duplicated in the saved page.

What code does.
1) Upon right click on webpage it will call the mod.php script to save the html DOM contents

Please check bottom of the page for code.

Issue observed in the m.amazon.com page:
--------------------------------------
Before saving the html
-----------------------------

<div class="toTheEdge dpSectionBodyText" style="text-align:center;">
</div><br /><div class="gw campaign center">
<a href="http://www.amazon.com/gp/aw/d/B00974L4D2/ref=me_amb_1628321722_1/179-6930500-7904300?aid=aw_gw&amp;apid=1628321722&amp;arc=1201&amp;arid=1XZK4FH47QXR2FAA2YAH&amp;asn=center-8">
<div id="ns_1XZK4FH47QXR2FAA2YAH_6645_" style="width:290px;height:50px;"></div>
<script type="text/javascript">
window.addEventListener('load', function() {
var container = document.getElementById('ns_1XZK4FH47QXR2FAA2YAH_6645_');
var img = document.createElement('img');
img.src="http://g-ecx.images-amazon.com/images/G/01/img13/amazon-mobile-apps/banners/amz-w_iphone5-cases_mob_580x100._V355491549_.jpg";
img.width="290";
img.height="50";
container.appendChild(img);
});

After saving the html
---------------------------

<div class="toTheEdge dpSectionBodyText" style="text-align:center;">
</div><br><div class="gw campaign center">
<a href="http://www.amazon.com/gp/aw/d/B00974L4D2/ref=me_amb_1628321722_1/179-6930500-7904300?aid=aw_gw&amp;apid=1628321722&amp;arc=1201&amp;arid=1XZK4FH47QXR2FAA2YAH&amp;asn=center-8">
<div id="ns_1XZK4FH47QXR2FAA2YAH_6645_" style="width:290px;height:50px;"><img src="http://g-ecx.images-amazon.com/images/G/01/img13/amazon-mobile-apps/banners/amz-w_iphone5-cases_mob_580x100._V355491549_.jpg" height="50" width="290"></div>
<script type="text/javascript">
window.addEventListener('load'
, function() {
var container = document.getElementById('ns_1XZK4FH47QXR2FAA2YAH_6645_');
var img = document.createElement('img');
img.src="http://g-ecx.images-amazon.com/images/G/01/img13/amazon-mobile-apps/banners/amz-w_iphone5-cases_mob_580x100._V355491549_.jpg";
img.width="290";
img.height="50";
container.appendChild(img);
});
----------------------------------------------------------------------------------------------------------



sendHtml() function should be changed like this :

function sendHtml() {

var getDocTypeAsString = function () {
var node = document.doctype;

return node ? "<!DOCTYPE "
+ node.name
+ (node.publicId ? ' PUBLIC "' + node.publicId + '"' : '')
+ (!node.publicId && node.systemId ? ' SYSTEM' : '')
+ (node.systemId ? ' "' + node.systemId + '"' : '')
+ '>\n' : '';
};

var html = getDocTypeAsString() + document.documentElement.outerHTML;

$.ajax({
url: 'mod.php',
data: {'content': html},
type: 'POST',
dataType: 'text',
success: function() {},
error: function(xhr, error) {
alert ('Error: ' + error);
}
});
}


PHP Script : 'mod.php '

<?php
if (!is_writable("index.html")) {
echo "File not writable!";
die();
}

$handle = fopen("index.html", "w");

if (!$handle) {
echo "File open failed";
die();
}

echo "content length: " . strlen($_POST['content']) . "\n";

$bytesWritten = fwrite($handle, $_POST['content'], strlen($_POST['content']));

if ($bytesWritten === false) {
echo "fwrite() failed!";
die();
}

echo "Wrote " . $bytesWritten . " bytes";

fclose($handle);
?>