Wrox Programmer Forums
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 10th, 2006, 10:28 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 140
Thanks: 0
Thanked 0 Times in 0 Posts
Default IFRAME Problem

Hallo,

I have already desaigned a javascript to manipulate a page but I have to show it in a new page with an invisible IFRAME. The code is

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script type="text/javascript" language="javascript">
function start() {
     var objIFrame = document.getElementById("IFrame1") ;
     var srcHTML = objIFrame.contentWindow.document.documentElement;
     window.alert(srcHTML);
     var mybody = srcHTML.getElementsByTagName("body")[0];
    window.alert(mybody);
    var myDiv = mybody.getElementsByTagName("div")[2];

    mytable = document.createElement("table");
    mytablebody = document.createElement("tbody");
    // creating all cells

            // creates a <tr> element
            mycurrent_row = document.createElement("tr");

                // creates a <td> element
                mycurrent_cell = document.createElement("td");
                // creates a Text Node
                currenttext = document.createTextNode("Link" );
                // appends the Text Node we created into the cell <td>
                mycurrent_cell.appendChild(currenttext);

                // appends the cell <td> into the row <tr>
                mycurrent_row.appendChild(mycurrent_cell);
                  // appends the row <tr> into <tbody>
            mytablebody.appendChild(mycurrent_row);
                 // creates a <td> element
                mycurrent_cell2 = document.createElement("td");
                // creates a Text Node
                currenttext2 = document.createTextNode("Source" );
                // appends the Text Node we created into the cell <td>
                mycurrent_cell2.appendChild(currenttext2);
                // appends the cell <td> into the row <tr>
                mycurrent_row.appendChild(mycurrent_cell2);
                  // appends the row <tr> into <tbody>
            mytablebody.appendChild(mycurrent_row);
                // creates a <td> element
                mycurrent_cell3 = document.createElement("td");
                // creates a Text Node
                currenttext3 = document.createTextNode("Date" );
                // appends the Text Node we created into the cell <td>
                mycurrent_cell3.appendChild(currenttext3);
                // appends the cell <td> into the row <tr>
                mycurrent_row.appendChild(mycurrent_cell3);
                  // appends the row <tr> into <tbody>
            mytablebody.appendChild(mycurrent_row);
                // creates a <td> element
                mycurrent_cell4 = document.createElement("td");
                // creates a Text Node
                currenttext4 = document.createTextNode("Words" );
                // appends the Text Node we created into the cell <td>
                mycurrent_cell4.appendChild(currenttext4);
                // appends the cell <td> into the row <tr>
                mycurrent_row.appendChild(mycurrent_cell4);
                  // appends the row <tr> into <tbody>
            mytablebody.appendChild(mycurrent_row);
                // creates a <td> element
                mycurrent_cell5 = document.createElement("td");
                // creates a Text Node
                currenttext5 = document.createTextNode("Language" );
                // appends the Text Node we created into the cell <td>
                mycurrent_cell5.appendChild(currenttext5);
                // appends the cell <td> into the row <tr>
                mycurrent_row.appendChild(mycurrent_cell5);
                  // appends the row <tr> into <tbody>

         mytablebody.appendChild(mycurrent_row);
       var i = 2;
       do {
              table = myDiv.getElementsByTagName("table")[i];
              row = table.getElementsByTagName("tr")[0];
              col = row.getElementsByTagName("td")[0];
              span = col.getElementsByTagName("span")[0];
              spanT = span.firstChild.nodeValue;
              col2 = row.getElementsByTagName("td")[1];
              anch = col2.getElementsByTagName("A")[0];
              childAnch = anch.firstChild.nodeValue;
              lSpan = col2.getElementsByTagName("span")[0];
              lSpan1 = lSpan.firstChild.nodeValue;
              myArray = lSpan1.split(/,/);
              var j = 0;
              /*do{
                 window.alert(myArray[j]);
                 j++;
                 }
              while(j<myArray.length) */

              text= spanT+" "+childAnch+" "+lSpan1;
              //window.alert(text);

            myRow = document.createElement("tr");
            myTd1 = document.createElement("td");
            myText1 = document.createTextNode(spanT+" "+childAnch+" ");
            myTd1.appendChild(myText1);
            myRow.appendChild(myTd1);
            mytablebody.appendChild(myRow);
            myTd2 = document.createElement("td");
            myText2 = document.createTextNode (myArray[0]);
            myTd2.appendChild(myText2);
            myRow.appendChild(myTd2);
            mytablebody.appendChild(myRow);
            myTd3 = document.createElement("td");
            myText3 = document.createTextNode (myArray[1]);
            myTd3.appendChild(myText3);
            myRow.appendChild(myTd3);
            mytablebody.appendChild(myRow);
            myTd4 = document.createElement("td");
            myText4 = document.createTextNode (myArray[2]);
            myTd4.appendChild(myText4);
            myRow.appendChild(myTd4);
            mytablebody.appendChild(myRow);
            myTd5 = document.createElement("td");
            myText5 = document.createTextNode (myArray[3]);
            myTd5.appendChild(myText5);
            myRow.appendChild(myTd5);
            mytablebody.appendChild(myRow);
            mytable.appendChild(mytablebody);
            if(mybody!=null)
               mybody.appendChild(mytable); //p = document.createElement("p");
              //currentText= document.createTextNode(spanT+" "+childAnch+" "+lSpan1);
              //p.appendChild(currentText);
              //mybody.appendChild(p);
              i++;
        } while (myDiv.getElementsByTagName("table")[i] != null)
        mytable.setAttribute("border","2");


}
</script>
</head>

<body onLoad="start()">
<IFRAME ID="IFrame1" FRAMEBORDER=0 SCROLLING=NO style="width:0px; height:0px; border: 0px"
src="file:///X|/Private/Factiva/Factiva1.htm"></IFRAME>

</body>
</html>


This code gives here the invalid argument error here

 mybody.appendChild(mytable);

But this code works completely without any errors (except the first two lines of the javascrupt which I didn't use in that way) in the source of IFRAME link. How can I solve this problem?


Your attitude determines your altitude

Your attitude determines your altitude
__________________
Your attitude determines your altitude
 
Old July 21st, 2006, 05:11 PM
Friend of Wrox
 
Join Date: Jun 2005
Posts: 244
Thanks: 3
Thanked 4 Times in 4 Posts
Default

try changing the id attribute to the name attribute still with the same value, taht might sort it out

------------------------------------------------
Apocolypse2005
Always ready and waiting to help!





Similar Threads
Thread Thread Starter Forum Replies Last Post
iframe refresh problem haieshwar Javascript 3 January 17th, 2007 06:59 PM
IFRAME Problem NEO1976 Javascript How-To 0 July 10th, 2006 10:13 AM
iframe bookmark problem reberman Javascript How-To 0 December 20th, 2005 12:38 AM
Cascading iframe problem nerssi HTML Code Clinic 0 June 13th, 2005 04:36 AM
problem in getting innerText of iframe BurhanKhan Javascript 6 August 24th, 2004 10:55 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.