
Originally Posted by
jscheuer1
Does this work repeatedly? Like could you keep switching the content with various and/or the same script with the same and/or different content, essentially importing multiple times without there being some collisions?
Yes, it's supposed to work repeatedly, with the same or different content.

Originally Posted by
jscheuer1
What about default content - content that's already in the div on page load? What happens to that if you want to get it back later after replacing it and have no external page for it?
There should not be static default content. Dynamically inserted default content can be imported via 'onload'.

Originally Posted by
jscheuer1
Anyways, I'm finding I have to click on the link twice or three times to get it to work. That's in Firefox, Chrome and IE the first time I view the page or if I clear the cache between attempts. In Opera - always.
That's strange. It worked here with all the major modern browsers (and even with IE6). I cannot check it now, because I don't have access to a decent browser right now. Did you (1) try the 'second' script and (2) put the css of the files_to_be_included in the head of the main page?
Could you try this:
Code:
<!-- Valid doctype here -->
<html>
<head>
<link rel="stylesheet" type="text/css" href="flexdropdown.css" />
<link rel="stylesheet" type="text/css" href="anylinkcssmenu.css" />
<script type="text/javascript">
var str = '';
/*Creating an (invisible) iframe for importing external content and a div for importing external scripts. The script as a whole won't work in IE7 if we do it the standard DOM way. So I use document.write*/
document.write('<iframe style="position:absolute; left: -10000px; width: 30px; height: 30px; display: none" name="ifr"><\/iframe>')
document.write('<div id="script_container" style="display:inline"><\/div>')
/* Specifying the url of the external page that we want to put in the iframe and, subsequently, extract from the iframe */
function get_url(url)
{
frames['ifr'].location.replace(url)
}
/* Representing the source of the iframe (used to extract external content) as a string */
function create_string()
{
str=frames['ifr'].document.documentElement.innerHTML;
}
/* Inserting the string into a div of our choice, and interpreting the code that may be contained in the string. */
function include(content,div)
{
document.getElementById(div).innerHTML=content;
var html_doc = window.frames.ifr.document;
var js = html_doc.createElement('script');
js.type="text/javascript";
js.text='function bring_code_to_main(){var el = document.getElementsByTagName("script");var search_limit = el.length-1;for(var x=0; x < search_limit; x++){newScript = top.document.createElement("script");newScript.type = "text/javascript";if(el[x].src != "") {newScript.src=el[x].src;newScript.text=""} else {newScript.text = el[x].text;}top.document.getElementById("script_container").innerHTML="";top.document.getElementById("script_container").appendChild(newScript);}};setTimeout("bring_code_to_main()",0)'; html_doc.getElementsByTagName('body').item(0).appendChild(js);
}
/* Making it work*/
function iframe_include(url,div)
{where=div
get_url(url);setTimeout("create_string();include(str,where)",200)
}
</script>
</head>
<body >
<a href="javascript: void(0)" onclick="iframe_include('flexmenu.html','some_div');">include flex</a><br>
<a href="javascript: void(0)" onclick="iframe_include('anylinkmenu.html','some_div');">include anylink</a><br>
<div id="some_div"></div>
It works with me, provided we have a standalone anylink menu and a standalone flex menu.
===
Arie.
Bookmarks