William Starr Moake wrote:
function saveFrame() {
imgSrcArray() = new Array
"()" is the call operator, used for function/method calls only which
is why you get the "cannot assign to function result" and "imgSrcArray
undefined" errors.
var imgSrcArray = new Array;
if(imgSrc.indexOf("\\") > -1)
You are using evil[tm] globals where not necessary.
{
slash = imgSrc.lastIndexOf("\\");
`slash' is defined global here. Use the `var' keyword instead.
imgSrcArray[imgSrcArray.length][0] = imgSrc
imgSrcArray exists. imgSrcArray[imgSrcArray.length] exists, as it
is always equivalent to imgSrcArray[0] here (since you reinitialize
imgSrcArray every time the method is called, it contains no elements
on this line). But imgSrcArray[imgSrcArray.length][0] as well as the
equivalent imgSrcArray[0][0] do not exist. Reason: There is no object
to which to add the property `0'. Solution: Create the object (array
element) first, assign the reference to it to imgSrcArray[...] and then
add the property to it:
imgSrcArray[imgSrcArray.length] = new Object(); // or Array
// note that we added an element previously
// vvv
imgSrcArray[imgSrcArray.length - 1][0] = imgSrc;
imgSrcArray[imgSrcArray.length][1] = imgSrc.substring(slash + 1,
imgSrc.length);
The same here. imgSrcArray[imgSrcArray.length] has
the value `undefined' until you assign a value to it.
[...]
var html = iView.document.documentElement.outerHTML;
iView.document.write(HTML);
iView.document.execCommand("SaveAs");
}
As for the rest, your algorithm can certainly be improved. Why
haven't you considered mine? <40**************@PointedEars.de>
There is no need for an array anyway and there is no need to replace
the whole source only for image path conversion. Not only this is
inefficient, you are risking undesired side effects. Since it seems
you code for IE, you *could* use
function abs2rel(d)
{
if (d && typeof d.images != "undefined")
{
for (var i = 0, imgs = d.images, len = imgs.length;
i < len;
i++)
{
imgs[i].src = imgs[i].src.replace(/\\/g, "/").replace(/.*\//, "");
}
}
}
abs2rel(iView.document);
which does what your code does.
But note that neither your algorithm nor my second one will successfully
convert absolute to relative paths. For that, stripping the directory path
is not enough, you need to determine what directory is the local document
root first and then strip it as prefix, as I already explained when posted
my first algorithm (see the above message-id).
HTH
PointedEars