473,396 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

image path conversion script

This is for a browser-based WYSIWYG editor to convert image file paths
from absolute to relative when the page under construction is saved.
From inside the save function I get error message: "Cannot assign to
function result." If I place just the HTML.replace part of the
conversion script inside the save function and the rest outside, the
error message is "imgSrcArray undefined." Can anyone figure out what
is wrong with this path conversion script? The save function works by
itself.

function saveFrame() {
imgSrcArray() = new Array
if(imgSrc.indexOf("\\") > -1)
{
slash = imgSrc.lastIndexOf("\\");
imgSrcArray[imgSrcArray.length][0] = imgSrc
imgSrcArray[imgSrcArray.length][1] = imgSrc.substring(slash + 1,
imgSrc.length);
}
if(imgSrc.indexOf("/") > -1)
{
slash = imgSrc.lastIndexOf("/");
imgSrcArray[imgSrcArray.length][0] = imgSrc
imgSrcArray[imgSrcArray.length][1] = imgSrc.substring(slash + 1,
imgSrc.length);
}
for (i=0; i<imgSrcArray.length; i++)
{
HTML = HTML.replace("<img src='"+imgSrcArray[i][0],"<img
src='"+imgSrcArray[i][1])
}
var html = iView.document.documentElement.outerHTML;
iView.document.write(HTML);
iView.document.execCommand("SaveAs");
}
Jul 23 '05 #1
1 1940
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
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Michael J. Astrauskas | last post by:
I have a script, which I've called test-loadpic.php and some pages reference it by means of <img src="test-loadpic.php?sourcepic=$picNum"> where $picNum stores a number. This part itself works...
3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
0
by: amita | last post by:
hi, 1.I want to show a image file of type '.tif' in the browser window; for that I'm writting as ASP code page. 2.This '.tif' type image can be shown better with 'Kodak Image Control'. 3.To...
7
by: Scott Schluer | last post by:
Is there a way to use the Image class to convert a color photo (GIF or JPEG) to a B&W photo? Thanks, Scott
15
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the...
4
by: tshad | last post by:
I am trying to set up an Image authorization where you type in the value that is in a picture to log on to our site. I found a program that is supposed to do it, but it doesn't seem to work. ...
4
by: yatin | last post by:
hi, friend. i have a problem in image validation plz check it. i have to include a image validation in foam 1. but i sending a details through form2. But when i include a image validation in foam1,...
11
by: Evolution445 | last post by:
I got this code, and it somehow doesnt work. <TABLE WIDTH=100% BORDER=0 CELLPADDING=0 CELLSPACING=0 align="center"> <TR> <TD background="{image-path}navfiller.gif" HEIGHT=40...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.