Simulate click inside iframe with JavaScript or jQuery -
this question has answer here:
- jquery trigger click on iframe? 2 answers
i have html containing iframe , 2 buttons, master , slave. slave displays "clicked" upon being clicked on while master simulates clicking action. works fine, i'd same behavior applied slave inside iframe. possible achieve such functionality? current code ignores iframe.
$(document).ready(function() { $('#master').click(function() { simulateclick(50, 50); //iframe position simulateclick(50, 100); //slave position }); $('#slave').click(function() { alert('clicked'); }); }); function simulateclick(x, y) { jquery(document.elementfrompoint(x, y)).click(); }
the document ready function not guarantee iframe has loaded. guess running before iframe has loaded. try like:
$(document).ready(function () { $('#iframeid').load(function () { $('#master').click(function() { simulateclick(50, 50); //iframe position simulateclick(50, 100); //slave position }); $('#slave').click(function() { alert('clicked'); }); }); });
Comments
Post a Comment