Forum Moderators: mack

Message Too Old, No Replies

need to access iframe content from the outside shell

iframe, javascript

         

Alla Gringaus

8:29 pm on Jul 21, 2003 (gmt 0)

10+ Year Member



Hi, thanks in advance!
I have an iframe, and as I go through the pagination, I wrote Javascript, which changes the source of the iframe's content. It looks like this:

¦=============¦
¦ ¦
¦ ¦
¦ ¦
¦ ¦
¦ ¦
¦=============¦

"send to a friend" prev 1¦2¦3¦ next

for 'send to a friend' in the iframe, i will need to access the contents of the iframe from the outer shell
something like parent.frames['i1'].getElementById('divname').innerHTML (not sure!)

i will have to wrap the inner content in divs or spans so they will be able to be accessed by the above string (or something like it)

So, the question is: can I get that data from the iframe and ready to be used in the shell?

The Javascript that I use to paginate through the sources of the iframe is as follows:

<script language="JavaScript" TYPE="text/javascript"><!--
var nextnum = 1;
if (nextnum == "") {nextnum = 1;}
function initPagination(pagenum, pagecount) {
if (pagecount <= 10) {
name = "cgp"+pagenum;
a = document.getElementById(name);
a.setAttribute("className", "navbar");
} else {
document.getElementById('number_span').innerHTML = pagenum;
}
}
function setPage(n)
{
reload(1);
name = "cgp"+nextnum;
a = document.getElementById(name);
a.setAttribute("className", "navbar_off");
nextnum = n;
name = "cgp"+nextnum;
a = document.getElementById(name);
a.setAttribute("className", "navbar");
}

function getNext (pagecount){
reload(1);
if (pagecount <= 10) {
name = "cgp"+nextnum;
a = document.getElementById(name);
a.setAttribute("className", "navbar_off");
}
nextnum = (nextnum == 5)? 1 : nextnum+1;
iframeUrl = "/getgoodgarden/iframe/0,17584,465017_SNK,00.html";
var iframeUrl = iframeUrl.replace(/SNK/,nextnum);
frames['i1'].location.href = iframeUrl;
if (pagecount <= 10) {
name = "cgp"+nextnum;
a = document.getElementById(name);
a.setAttribute("className", "navbar");
} else {
document.getElementById('number_span').innerHTML = nextnum;
}
}

function getPrev (pagecount){
reload(1);
if (pagecount <= 10) {
name = "cgp"+nextnum;
a = document.getElementById(name);
a.setAttribute("className", "navbar_off");
}
nextnum = (nextnum == 1)? 5 : nextnum-1;
iframeUrl = "/getgoodgarden/iframe/0,17584,465017_SNK,00.html";
var iframeUrl = iframeUrl.replace(/SNK/,nextnum);
frames['i1'].location.href = iframeUrl;
if (pagecount <= 10) {
name = "cgp"+nextnum;
a = document.getElementById(name);
a.setAttribute("className", "navbar");
} else {
document.getElementById('number_span').innerHTML = nextnum;
}
}
if(document.all &&!document.getElementById) {
document.getElementById = function(id) {
return document.all[id];
}
}
function reload(_v)
{
if (_v==1)
{
document.all.i2.src=/adframe/0,17610,93171904,00.html';
}
}
function writePrint() {
var agent = navigator.userAgent.toLowerCase();
if (agent.lastIndexOf('mac') < 0) {
document.write('<a href=javascript:printFrame("i1");><IMG src="/images/nav_button_print.gif" width=56 height=24 border=0 alt="print this"></a>');
}
}
function printFrame (f) {
eval("parent."+f+".focus()");
eval("parent."+f+".print()");
}
//-->
</script><SCRIPT LANGUAGE="JavaScript1.1" SRC="../file/adsWrapper.js" TYPE="text/javascript"></SCRIPT>
<script language="JavaScript" TYPE="text/javascript"><!--
var agent = navigator.userAgent.toLowerCase();
var is_gecko = agent.indexOf("gecko")!= -1;
function init() {
var myW = 749;
var myHsh = document.body.scrollHeight + 4;
var myH = screen.availHeight-window.screenTop-36;
if (myHsh < myH) myH = myHsh;
self.resizeTo(myW,myH);
adjW = ((screen.width - myW) / 2);
window.moveTo(adjW);
}

function modLinks() {
var link, l = 0;
while (link = document.links[l++]) {
if (link.href.indexOf('.......com') == -1 && link.href.indexOf('javascript:') == -1 && link.target.indexOf('i1') == -1 && link.href.indexOf('aol://5863') == -1 && link.href.indexOf(........com') == -1) link.target = '_blank';
}
}
start = agent.indexOf("aol") + 3;
end = agent.indexOf(";",start);
aol_str = agent.substring(start,end);
aol_vers = parseInt(aol_str);
if (aol_vers > 6) {
//this.onload = modLinks
this.onload = init
}
//-->
</script>

broniusm

8:57 pm on Jul 21, 2003 (gmt 0)

10+ Year Member



I'd recommend trimming your posted code to only the code in question.. but on to important things:
So, the question is: can I get that data from the iframe and ready to be used in the shell?

Sure can, and this is really close:
parent.frames['i1'].getElementById('divname').innerHTML

Try instead:

window.frames['i1'].document.getElementById('divname').innerHTML;

(I added 'document', and I changed 'parent' to 'window' b/c your sendToFriend link is already in the shell, not the inner frame, correct?

Also, this post is off the top of my head-- I'm only assuming your code doesn't work and your question is why not...! :)

Alla Gringaus

12:50 pm on Jul 22, 2003 (gmt 0)

10+ Year Member



Thanks for your response. I tried this:
<script language = "javascript">
function sendEmail() {

var emailBody;
var emailTo;
var emailSubject;
var emailCC;
var emailBCC;
var emailURL;
emailTo = ""
emailBody = (window.frames['i1'].document.getElementById('framedata').innerHTML)
emailSubject = ""
emailCC = ""
emailBCC = ""
emailReplyTo = ""
emailURL = "mailto:" + escape(emailTo) +
"?subject=" + escape(emailSubject) +
"&cc=" + escape(emailCC) +
"&bcc=" + escape(emailBCC) +
"&replyto=" + escape(emailReplyTo) +
"&body=" + escape(emailBody);
window.location = emailURL;
return true;
}

</script>

It sends the code of the HTML like the tags, <> ... </...>. I tried InnerText, but only the text gets emailed. I would need to send the whole entire HTML, with the picture from the iframe - whatever's there.

Thanks.

broniusm

4:50 pm on Jul 22, 2003 (gmt 0)

10+ Year Member



I would need to send the whole entire HTML, with the picture from the iframe - whatever's there.

OIC. That's a bit more complicated. As I understand, in order to collect images, the images have to be presented as urn's, which you would get from .innerHTML. The images would need to be first uploaded to the server, then referenced within that msg iframe as a an img tag linked in. How you upload the images (whether automatically somehow or manually with an insert & file browse form element) is up to you.

See one in action: step through the execution, using MS Script Debugger, of composing a Hotmail message with "Rich Editor" on and inserting an image. I know you can even copy/paste an image in, if it's accessible on the web somewhere, and the result is an img and urn.

Please do keep this thread posted with your progress/results.

sryoung

7:21 pm on Jul 25, 2003 (gmt 0)



I am trying to do something very similar
i have an iframe that i want to capture the content of
i'm trying this

alert(document.frames['contentIF'].document.documentElement.outerHTML)

it works but i get an error as well....

any help?

kamikaze Optimizer

11:22 pm on Jul 25, 2003 (gmt 0)

10+ Year Member



Just curious, but with what browsers does the iframe work with? I know with my IE 6.0.2800 set at default, it does not work.