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