By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,282 Members | 1,207 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,282 IT Pros & Developers. It's quick & easy.

Getting information from a hidden IFrame

P: n/a
This might beyond the scope of this group because it deals with
SharePoint, but I'm not sure if I can't get it to work because of
SharePoint or because JavaScript is weird (I don't have much experience
with JavaScript).

Anyway, here is the code i'm working with. Basically, it creates
appends a hidden IFrame to the page, gets the links from the IFrame,
and displays those which have the "OnLink" property. The weird thing
is that when I uncomment out the alert("x=0") line, it works fine. If
I don't have an alert, then nothing will be written to the page (the
page already exists, I'm adding the JavaScript to the page as a Content
Editor Web Part).

var links;
var hiddenIframe = document.createElement("IFRAME");
var linksArray = new Array();
var x = null;

hiddenIframe.id = "iLinks";
hiddenIframe.style.display = "none";
hiddenIframe.src = "source of links";
WebPart_WPQ_.appendChild(hiddenIframe);

links = frames["iLinks"].document.getElementsByTagName("A");
x = 0;
//alert("x=0");

for (var i=0; i<links.length; i++)
{
var templink = links(i);
var onValues = templink.onclick + templink.onfocus + "";

if(onValues.indexOf("OnLink") >= 0)
{
linksArray[x] = templink;
x++;
}
}

for (var j=0; j<linksArray.length; j++) {
document.write(linksArray[j] + '<br>');
}

I also tried an alternate solution where I called everything function
on IFrame onLoad, but that deleted everything on the page and wrote the
text instead of writing the text to the specific area where the
function was located (as it does when the alert("x=0") is uncommented
on the above code).

Thanks in advance for any help.

Oct 18 '06 #1
Share this Question
Share on Google+
4 Replies

P: n/a
Any ideas?

Drew wrote:
This might beyond the scope of this group because it deals with
SharePoint, but I'm not sure if I can't get it to work because of
SharePoint or because JavaScript is weird (I don't have much experience
with JavaScript).

Anyway, here is the code i'm working with. Basically, it creates
appends a hidden IFrame to the page, gets the links from the IFrame,
and displays those which have the "OnLink" property. The weird thing
is that when I uncomment out the alert("x=0") line, it works fine. If
I don't have an alert, then nothing will be written to the page (the
page already exists, I'm adding the JavaScript to the page as a Content
Editor Web Part).

var links;
var hiddenIframe = document.createElement("IFRAME");
var linksArray = new Array();
var x = null;

hiddenIframe.id = "iLinks";
hiddenIframe.style.display = "none";
hiddenIframe.src = "source of links";
WebPart_WPQ_.appendChild(hiddenIframe);

links = frames["iLinks"].document.getElementsByTagName("A");
x = 0;
//alert("x=0");

for (var i=0; i<links.length; i++)
{
var templink = links(i);
var onValues = templink.onclick + templink.onfocus + "";

if(onValues.indexOf("OnLink") >= 0)
{
linksArray[x] = templink;
x++;
}
}

for (var j=0; j<linksArray.length; j++) {
document.write(linksArray[j] + '<br>');
}

I also tried an alternate solution where I called everything function
on IFrame onLoad, but that deleted everything on the page and wrote the
text instead of writing the text to the specific area where the
function was located (as it does when the alert("x=0") is uncommented
on the above code).

Thanks in advance for any help.
Oct 20 '06 #2

P: n/a
ASM
Drew a écrit :
>Anyway, here is the code i'm working with. Basically, it creates
appends a hidden IFrame to the page, gets the links from the IFrame,
and displays those which have the "OnLink" property. The weird thing
is that when I uncomment out the alert("x=0") line, it works fine. If
I don't have an alert, then nothing will be written to the page (the
page already exists, I'm adding the JavaScript to the page as a Content
Editor Web Part).
with the complet function or an example in line
it would have been better ...
>>
var links;
var hiddenIframe = document.createElement("IFRAME");
var linksArray = new Array();
var x = null;

hiddenIframe.id = "iLinks";
hiddenIframe.style.display = "none";
hiddenIframe.src = "source of links";
perhaps you need new iframe finish to load the file "source of links" ?

hiddenIframe.onload = function() {
// don't forget to close this function at end of script
>links = frames["iLinks"].document.getElementsByTagName("A");
x = 0;
//alert("x=0");

for (var i=0; i<links.length; i++)
{
var templink = links(i);
var onValues = templink.onclick + templink.onfocus + "";

if(onValues.indexOf("OnLink") >= 0)
{
linksArray[x] = templink;
x++;
}
}
for (var j=0; j<linksArray.length; j++) {
document.write(linksArray[j] + '<br>');
}
var txt = '';
for (var j=0; j<linksArray.length; j++) txt += linksArray[j] + '<br>';
document.write(txt); // that would have to write in hidden iframe

} // supposed end of iframe's onload function

WebPart_WPQ_.appendChild(hiddenIframe);

}

>I also tried an alternate solution where I called everything function
on IFrame onLoad, but that deleted everything on the page and wrote the
text instead of writing the text to the specific area where the
function was located (as it does when the alert("x=0") is uncommented
on the above code).
the onload is to be set before the appendChild

and ... specific areas ... how to consider them with a bit of code as
given ?

you want that write on main page ?
parent.document.write(txt); // would have to write in main page

to write (or add) to div 'someWhere' on main page :
parent.document.getElementById('someWhere').innerH TML = txt;
--
ASM
Oct 20 '06 #3

P: n/a
that actually was the complete function. the rest of the page is
automatically created by sharepoint, which i have no control over it
(which is why we're trying to use scripts so we can get more out of
sharepoint). the original code given will write directly to the parent
page, which is what i want. here is the alternate script was referring
to:

<script language="JavaScript">
var links;
var linksArray = new Array();
var contentsArray = new Array();
var x = null;
function getLinks()
{
links = frames["iLinks"].document.getElementsByTagName("A");

x = 0;

for (var i=0; i<links.length; i++)
{
var templink = links(i);
var onValues = templink.onclick + templink.onfocus + "";
if(onValues.indexOf("OnLink") >= 0)
{
linksArray[x] = templink;
contentsArray[x] = links(i).innerHTML;
x++;
}
}
writeLinks();
}

function writeLinks()
{
for (var j=0; j<linksArray.length; j++)
{
parent.document.write(contentsArray[j].link(linksArray[j]) +
'<br>');
}
}

function mainFunc()
{
var hiddenIframe = document.createElement("IFRAME");
hiddenIframe.attachEvent("onload", getLinks);
hiddenIframe.id = "iLinks";
hiddenIframe.style.display = "none";
hiddenIframe.src =
"http://teamsites.wachovia.net/it/communications/ITIGProjectCenter/testcenter2/Lists/Links/AllItems.aspx";
WebPart_WPQ_.appendChild(hiddenIframe);
}

window.attachEvent("onload", mainFunc);
</script>


this script, however, will clear the entire sharepoint page and write
the first link of the array.

ASM wrote:
Drew a écrit :
Anyway, here is the code i'm working with. Basically, it creates
appends a hidden IFrame to the page, gets the links from the IFrame,
and displays those which have the "OnLink" property. The weird thing
is that when I uncomment out the alert("x=0") line, it works fine. If
I don't have an alert, then nothing will be written to the page (the
page already exists, I'm adding the JavaScript to the page as a Content
Editor Web Part).

with the complet function or an example in line
it would have been better ...
>
var links;
var hiddenIframe = document.createElement("IFRAME");
var linksArray = new Array();
var x = null;

hiddenIframe.id = "iLinks";
hiddenIframe.style.display = "none";
hiddenIframe.src = "source of links";

perhaps you need new iframe finish to load the file "source of links" ?

hiddenIframe.onload = function() {
// don't forget to close this function at end of script
links = frames["iLinks"].document.getElementsByTagName("A");
x = 0;
//alert("x=0");

for (var i=0; i<links.length; i++)
{
var templink = links(i);
var onValues = templink.onclick + templink.onfocus + "";

if(onValues.indexOf("OnLink") >= 0)
{
linksArray[x] = templink;
x++;
}
}
for (var j=0; j<linksArray.length; j++) {
document.write(linksArray[j] + '<br>');
}

var txt = '';
for (var j=0; j<linksArray.length; j++) txt += linksArray[j] + '<br>';
document.write(txt); // that would have to write in hidden iframe

} // supposed end of iframe's onload function

WebPart_WPQ_.appendChild(hiddenIframe);

}

I also tried an alternate solution where I called everything function
on IFrame onLoad, but that deleted everything on the page and wrote the
text instead of writing the text to the specific area where the
function was located (as it does when the alert("x=0") is uncommented
on the above code).

the onload is to be set before the appendChild

and ... specific areas ... how to consider them with a bit of code as
given ?

you want that write on main page ?
parent.document.write(txt); // would have to write in main page

to write (or add) to div 'someWhere' on main page :
parent.document.getElementById('someWhere').innerH TML = txt;
--
ASM
Oct 20 '06 #4

P: n/a
I finally figured it out. I think the problem was in the way
SharePoint was set up, it may have worked under different
circumstances. Here is my way around it though, if anyone is
interested:

<script language="JavaScript">
var links;
var linksArray = new Array();
var contentsArray = new Array();
var x = null;
var tbl = document.createElement("TABLE");
var tbody = document.createElement("TBODY");

function getLinks()
{
links = frames["iLinks"].document.getElementsByTagName("A");

x = 0;

for (var i=0; i<links.length; i++)
{
var templink = links(i);
var onValues = templink.onclick + templink.onfocus + "";
if(onValues.indexOf("OnLink") >= 0)
{
linksArray[x] = templink;
contentsArray[x] = links(i).innerHTML;
x++;
}
}
writeLinks();
}

function writeLinks()
{
for (var j=0; j<linksArray.length; j++)
{
var tr = document.createElement("TR");
var td = document.createElement("TD");
var aLink = document.createElement("A");
aLink.setAttribute("href", linksArray[j]);
aLink.appendChild(document.createTextNode(contents Array[j]));
td.appendChild(aLink);
tr.appendChild(td);
tbody.appendChild(tr);
}

tbl.appendChild(tbody);
WebPart_WPQ_.appendChild(tbl);
}

function mainFunc()
{
var hiddenIframe = document.createElement("IFRAME");
hiddenIframe.attachEvent("onload", getLinks);
hiddenIframe.id = "iLinks";
hiddenIframe.style.display = "none";
hiddenIframe.src = "URL of links list";
WebPart_WPQ_.appendChild(hiddenIframe);
}
window.attachEvent("onload", mainFunc);
</script>

Oct 20 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.