views:

34

answers:

4

Hello everyone.

I have an HtmlEditor from asp controltoolkit.
That creates an iframe with a couple things i need (bold letter, etc).
I need to add text to that iframe with jquery.
so long i have this.

$('#<%= tbDescripcionInsert.ClientID %>').contents().text(textoMercancia.substring(15, textoMercancia.length));

My problem is that the things im using from the editor (bold letter etc) disappear when i add the text from jquery.

What can it be?
What is the best way to add text into an iframe with jquery?

Thank you very much.

A: 

Try something like:

var d = $("#someFrame")[0].contentWindow.document; // contentWindow works in IE7 and FF d.open(); d.close(); // must open and close document object to start using it!

// now start doing normal jQuery:

$("body", d).append("ABC");

PriorityMark
i don't think all that is necessary
mcgrailm
didn't try it and don't know if it works but thank you anyway.
rolando
A: 

the problem is that

  .text('blahblah') 

replaces the text so you must use

 .append('blahblah') 

or some similar command

EDIT seeing your post this might be more effective

  $('#<%= tbDescripcionInsert.ClientID %>').contents().find('body').append('blahblah')
mcgrailm
hi mcgrailm, it doesn´t works because i have the same problem, it uses another portion of the iframe and not the one i need.
rolando
A: 

If you want to handle markup, not just text, use html() instead of text().

Christian Nesmark
hi christian, it doesn´t works because i have the same problem, it uses another portion of the iframe and not the one i need.
rolando
A: 

Thank you all for your help.

I found a way to solve this:

$('#<%= tbDescripcionInsert.ClientID %>_ctl02_ctl00').contents().children().children('body').html(textoMercancia.substring(15, textoMercancia.length));

this way i can access the exact part of the iframe where the information is supossed to be loaded. hope this help someone in the future.

rolando