/    Sign up×
Community /Pin to ProfileBookmark

Hello im using a execCommand(“InsertImage”, “”, strTag);

to insert an image into an iFrame, because the execCommand does not give the <img> tag a name im finding it hard to find a way to reference the element.

now i dont want to use the userInterface because i only want the user to select an image from a preset list.
If anyone can shed some light on this it would be greatly appreciated

Matt

to post a comment
JavaScript

12 Comments(s)

Copy linkTweet thisAlerts:
@Warren86Nov 24.2004 — Is this related to a previous post of yours concerning "editing" the HTML in an IFrame? If so, I have other code that might help. Otherwise, take a look at this.

<HTML>

<Head>

<Script Language=JavaScript>

Item = new Object
Item.A = "<img src='new1.jpg' width='100' height='150'>"
Item.B = "<img src='new2.jpg' width='120' height='210'>"
Item.C = "<img src='new3.jpg' width='190' height='105'>"
Item.D = "<img src='new4.jpg' width='65' height='50'>"

function xferText(curr){

isText = Item[curr]+"<br>";
txtFrame.document.write(isText);
}


</Script>

</Head>

<Body>

<IFRAME

Name = 'txtFrame'

Width = 200

Heigth = 50>

</IFRAME>

<br><br>

<input type=button value="Image A" onClick="xferText('A')">

<br>

<input type=button value="Image B" onClick="xferText('B')">

<br>

<input type=button value="Image C" onClick="xferText('C')">

<br>

<input type=button value="Image D" onClick="xferText('D')">

</Body>

</HTML>
Copy linkTweet thisAlerts:
@matt_carter_25authorNov 24.2004 — Thanks man,

This is a bit complex, i have an iframe which displays content from SQLServer as HTML, which is the content from a webpage.

Using idContent.document.body.innerHTML or write replaces whats in the iframe to start with.

I want to give the client the option of droping in an image into the text displayed in the iframe, however the choice of images they can use is restricted what they have previously uploaded.

So they click on the insertImage button this opens a window which gives them the choice of images they have and displays the image properties which can be edited (border, width ect) when they click insert, some javascript stores the properties and image path into a string which looks like:

var imgTag = "<img src='" + document.Mainimage.src + "'>"

now what i want to do is insert this tag into the iframe at the position of the cursor.

or i can use

imgTag = "http://www.allnut.com/images/home.gif"

execCommand("InsertImage", "", imgTag);

this will insert an image to cursor position but does not allow me to apply the attributes because the execCommand() does not give the img tag any ID or Name.

Not sure what to do really, maybe im asking too much of javascript

If annyone can help

Thanks

Matt
Copy linkTweet thisAlerts:
@Warren86Nov 24.2004 — Your response was very telling. Your concern seems to be whether you are "asking too much" of JavaScript. It seems to me that what you need is a paid consultant(s), not the volunteer assistance found on a web forum, such as this.
Copy linkTweet thisAlerts:
@matt_carter_25authorNov 24.2004 — Well Actually i have managed to get round the problem,

(Without having to get a paid consultant!)

imgTag = document.Mainimage.src + '"' + " width=" + imgWidth + " height=" + imgHeight + " border=" + imgBorder ;

and then use

execCommand("InsertImage", "", imgTag)

this cheats the tags quote marks and allows the attributes to be passed along with the imagepath!!!

Thanks for your help anyway
Copy linkTweet thisAlerts:
@KorNov 24.2004 — I tried a different aproach, but I stucked somewere. If you want, follow the thread

http://www.webdeveloper.com/forum/showthread.php?s=&threadid=49841

maybe we will find a DOM solution to that
Copy linkTweet thisAlerts:
@matt_carter_25authorNov 24.2004 — good idea but i dont think that is supported by iFrame
Copy linkTweet thisAlerts:
@KorNov 25.2004 — Should work, as the object in an iframe is easy to be manipulated from parent with top.frames['iframename'].object reference.
Copy linkTweet thisAlerts:
@matt_carter_25authorNov 25.2004 — The only problem is you have to use execCommand(), when this method creates a new object it doesnt give the obejct a name or ID so you cant reference it from the parent window.
Copy linkTweet thisAlerts:
@KorNov 25.2004 — 
you have to use execCommand(),
[/quote]


I tried to avoid it... Still I think i might do it on my way... any help around?
Copy linkTweet thisAlerts:
@matt_carter_25authorNov 26.2004 — Yeah sure,

When i insert a image i use:

execCommand("InsertImage", "", strImageName);

all you need to do is

strImageName = "anything.gif" + '"' + " ID=myGif border=1";

this will trick the tag, all it does is use the string for the image source but by adding the extra quotation marks you can pass any many attributes as you need,

Its a good work around

Matt
Copy linkTweet thisAlerts:
@LeWiNov 26.2004 — Salam

Sorry Guys

may i interupt u ??

Ummmmm

if u plz

what is the execCommand ??

and for what it can be used ?

---LeWi---
Copy linkTweet thisAlerts:
@matt_carter_25authorNov 26.2004 — execCommand() is used for adding elements into an iFrame because of the security with iFrame. if i want to drop an <img> tag into an iFrame i have to use from the parent window

execCommand("InsertImage","",strImageName)

this will drop the image into the iFrame where the cursor is placed.

if you would like to know more check out,

http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/objects/iframe.asp
×

Success!

Help @matt_carter_25 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...