I am trying to get a web page to print an element ID that has been clicked on (using an alert for now).
However, the web pages will be external sites (Google for example).
I have tried this with a new window and an iframe but cannot get the desired functionality. Would appreciate help with my JS functions as I am new with this technology.
function windowOpen() {
myWindow=window.open("http://www.google.com",'','width=1000,height=700');
myWindow.focus;
var tag;
onmouseclick = tag = "Element name: " + myWindow.event.srcElement.tagName + " ID: " + myWindow.event.srcElement.id;
alert(tag);
}
function hideShow() {
var myIframe = document.getElementById('myFrame');
var content ;
onmouseclick = tag = myIframe.contentDocument.element.id;
alert(content);
}
For security reasons, it is not possible to get the user’s browser to tell you things about data from other websites (i.e. keep your hands off my online banking).
The only way to do this from your own page would be to proxy the remote pages through your own server (and rewrite any relative URIs).
Alternatively, you could investigate writing a browser extension as this would have heightened privileges (since users must actively install them).