OK, hopefully this question isn’t too confusing…
I need to know if this is possible or not. I think not, but wanted to check anyway.
OK, in main browser window, we have what I will call “doc1”. Another page is opened with the Javascript open function, we will call this page “doc2”. What I need is for doc2 to be able to capture an onClick event that is triggered in doc1. I need to be able to capture the element that you click in. Imagine this scenario:
1. You open up a web page that has a form (doc1)2. You open up doc2 by clicking a button3. You click in a textarea in doc1, and doc2 is able to see which textearea element you clicked in.
I haven’t gotten this to work, however, and I think this might be violating some kind of built in Javascript security. Here is the code I started playing with, but didn’t really get anywhere. Looking for an idea that works, or a confirmation of my suspicion that I can’t do what I am trying to do.
Note: The two pages might not end up being from the same domain, so take that into consideration since I know Javascript has security checks for some cross-domain actions.
[code]
<!– doc1 –>
<html>
<head><title>clicktest</title>
<body>
<form name=”test” action=””>
<input type=”text” size=20><br>
<textarea name=”text” cols=60 rows=5></textarea><br>
<input type=”button”
onClick=”javascript:void(open(‘test2.html’,’test2′, ”));”
value=”Open Window”>
</form>
</body>
</html>
<!– end doc1 –>
<!– doc2 –>
<html>
<head>
<title>Test</title>
</head>
<body>
</body>
<script language=”javascript”>
alert(window.opener.document.title);
window.opener.document.onClick = doIt;
function doIt(evt) {
alert (“got here”);
if (evt.srcElement.type == “textarea” ||
evt.srcElement.type == “text”) {
alert (evt.srcElement.type);
evt.srcElement.value = “hello world?”;
}
}
</script>
</html>
<!– end doc2 –>