Reputation: 1
I need to click the button (without an id and name) inside an iframe (with an id and name) with using JavaScript/jQuery.
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js" type="text/javascript">
</script>
</head>
<body>
<iframe name="abb" id="abb" src="http://example.com" scrolling="no"frameborder="0" style="border:none; overflow:hidden; width:45px; left:-19px; height:21px; z-index: 0; position: relative;" allowTransparency="true"></iframe>
</div>
<script>
document.getElementById("abb").contentWindow.document.getElementsByName('REG_BTN')[0].click();
</script>
</body>
</html>
Upvotes: 0
Views: 931
Reputation: 1494
This is a way to locate the button:
var iframe = document.getElementById('iframeId'),
innerDocument = iframe.contentDocument || iframe.contentWindow.document,
button = innerDocument.getElementsByTageName('input')[0];
This will only work if the iframe origin from your server. This will find the first button, or <input>
. If there's more than one <input>
you could make a for loop and check for the 'button' type with getAttribute('button');
. This will help you doing the click simulation.
Upvotes: 0
Reputation: 594
you could always traverse it by using id or name of the tag that you do know
for example
$('body div.container div.panel>div.heading~div button').click();
Upvotes: 1
Reputation: 943097
You can't access the DOM of documents on other origins.
The closest you could come would be to send a message to the document which would have to include JS that listened for the message and responded accordingly.
Upvotes: 3