Forum Moderators: open
[webmasterworld.com...]
<html>
<script type="text/javascript; version=1.5">
function clickedhref() {
location.href="http://www.google.com";
alert('follow link');
document.getElementById('href="http://groups-beta.google.com/grphp?hl=en&tab=wg"').click();
}
</script>
<body onload="clickedhref()">
</body>
</html>
So I have taken google.com as my webpage and I am trying to click on a object that contains href as group-beta.google.com...
If any body know how I can Do this please suggest me.
Becoz in some webpages you will have scripts rather than direct URLs.
Thanks.
You use "getElementById" but don't use the id.
I've looked at the google page in question and the id of the link you want to simulate clicking is '2a'
Now the error "Object Expected" goes away.
Now you will get "Permission Denied".
I think that you will never be capable of simulating a click across domains because if you could, I can imagine lots of nasty things that people could be doing. I'm sure it would classify as a high security risk and though I don't know for certain, I guess it can't (and should not) be done.
You can link to a page but you can't manhandle it once you've pulled it up.
SuperN¤vaCain
ADDED:
What purpose do you have, that you need to navigate to a page outside of your domain, and then you need to "click" a link on that page, that accomplishes more than just linking to the final page? (Just wondering.)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>
adding click method to HTMLElement with Mozilla
</title>
<script type="text/javascript; version=1.5">
try {
// create span element so that HTMLElement is accessible
document.createElement('span');
HTMLElement.prototype.click = function () {
if (typeof this.onclick == 'function')
this.onclick({type: 'click'});
};
}
catch (e) {
alert('click method for HTMLElement couldn\'t be added')
}
try {
// create a element so that HTMLAnchorElement is accessible
document.createElement('a');
HTMLElement.prototype.click = function () {
if (typeof this.onclick == 'function') {
if (this.onclick({type: 'click'}) && this.href)
window.open(this.href, this.target? this.target : '_self');
}
else if (this.href)
window.open(this.href, this.target? this.target : '_self');
};
}
catch (e) {
alert('click method for HTMLAnchorElement couldn\'t be added')
}
</script>
<style type="text/css">
#testingDiv { background-color: lime; }
#testingDiv a:link { color: red; }
</style>
</head>
<body>
<div id="testingDiv">
These links are for calling the click methods of the elements below:
<a href="javascript: void 0"
onclick="document.getElementById('aDiv').click();
return false;"
>
click div
</a>
¦
<a href="javascript: void 0"
onclick="document.getElementById('aButton').click();
return false;"
>
click button
</a>
¦
<a href="javascript: void 0"
onclick="document.getElementById('link0').click();
return false;"
>
click link0
</a>
¦
<a href="javascript: void 0"
onclick="document.getElementById('link1').click();
return false;"
>
click link1
</a>
</div>
<div id="aDiv"
onclick="alert(this.id + ' ' + event.type + 'ed.')"
>
clickable div
</div>
<input type="button" id="aButton" value="clickable button"
onclick="alert(this.id + ' ' + event.type + 'ed.')"
/>
<br />
<a id="link0" href="http://www.kibo.com/">
link0 without onclick handler
</a>
<br />
<a id="link1" href="http://www.kibo.com/" target="_blank"
onclick="return confirm('Follow link?');"
>
link1 with onclick handler
</a>
</body>
</html>
Thanks everybody anyway.
Durga.