473,396 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Getting information from a hidden IFrame

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
4 2506
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Matt | last post by:
I want to open a page that is hidden to the user. Some people suggest me to use hidden iframe. Is it a good solution? Any good examples?
6
by: fniyogi | last post by:
Does anyone know how to suppress the "busy"/hourglass cursor that appears when a frame/iframe is loading, as in the g() functon below: <SCRIPT> function g() { if ( Math.floor(Math.random()*2)...
1
by: tllcll | last post by:
Hi, I would like to find out how to handle the following: I retrieve the data from the database by calling javabean and return the data back to the same jsp page and then display those values...
10
by: jon | last post by:
I'm trying to use a hidden iframe to print the contents of one div seamlessly. Currently I can create the hidden iframe, copy the contents of the div to the iframe, and print it. I even have a...
5
by: pbd22 | last post by:
hi. i have a hidden iframe for uploading files. when i check the httpfilecollection on the server, it is always zero - the files never make it to the server. i know all the javascript is working...
5
by: pbd22 | last post by:
Hi. I am trying to poll a long-running process via a hidden IFrame. I am noticing that the online errata gives advice for handling a server response: window.parent.handleServerResponse(); ...
1
by: Turin | last post by:
I'm trying to put a print button on a page that will open the print dialog box for a PDF that there is no need to open. My original plan was to use a hidden iframe calling a javascript function that...
6
by: buntyindia | last post by:
Hi, I have a page. There is a section 'sidebar' where bulleted text is there. Just after first bullet there is a hidden IFRAME. That go visible on clicking of that bullet text. My problem is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.