Yes, it's a crap shoot if you know what I mean. I think earlier versions of Firefox would execute something as simple as an alert. I really don't keep up on the behavior in any given browser with things like that because there is no cross browser method at that level.
However, there is a new paradigm emerging in javascript as it relates to imported AJAX content. First of all the script(s) you might want to run against imported content should be on the 'top' page. These scripts cannot initialize onload in the usual way that many scripts do though, because the imported content will not be there yet. Polling is one way to attempt to deal with this issue, but it is inefficient.
Here is a very simple example of a script that will run against imported content, as well as content already present on the page:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
document.onclick = function(e){
e = e || window.event;
var t = e.target || e.srcElement;
if (t.className == 'qualifies')
alert('AhHa!');
}
</script>
</head>
<body>
<span class="qualifies">Click Me</span><br>
<span>Click me, but no dice</span>
</body>
</html>
If you were to import content to that page that also had an element with the class 'qualifies', and you clicked on it, it would give the alert, just like the one that's hard coded on the page. This can work with very complex code, but if the element clicked is a child of a qualifying element, walking the DOM tree upward from it would be required - fairly simple actually, but not a part of this very basic demo.
This works because instead of initializing or coding to the imported content, the script in this case is listening to the document.
Now, you can also go to the other extreme and simply hard code events to imported elements, but in most cases for that to be effective, there would still need to be a script on the 'top' page to evaluate the events.
But a simple example can demonstrate this technique with no script on the 'top' page. On an external page you may have:
HTML Code:
<a href="#" onclick="alert('Hello World');return false">Say Hi</a>
If that is imported, it will work when clicked.
Bookmarks