0

I have a simple html page with an iframe image link. After the page loads I want the link to be clicked automatically. I need the link to be clicked instead of doing a meta refresh so thats out of the question. I searched around and It seems like FireFox does not support any methods to do so...There has to be a cross browser solution. Here is what I have so far but it wont work...why?

 <script type="text/javascript">
window.onload=functionName;
$(document).ready(function(){
  $('#clicked').trigger('click')
});
</script>

<div id="clicked">
      <iframe src="http://mysource.com" width="40" height="10" scrolling="no" border="0" marginwidth="0" style="border:none;" frameborder="0"></iframe>
  </div>
5
  • Invalid selector...but why are you trying to "click" a div anyway? Commented Jul 31, 2013 at 13:49
  • Brad- This project is to click an affiliate banner within a div that is on an html page as a temp splash page before the jump to the affiliate link. Commented Jul 31, 2013 at 14:05
  • I have found several posts on here and several other websites with a similar question and all the answers never produce a working answer for the questioner. An answer would help many people. Commented Jul 31, 2013 at 14:06
  • What you said doesn't make any sense. There is a reason browsers don't let you auto-click links. Commented Jul 31, 2013 at 14:07
  • Why would it not allow for that reason. That doesn't make sense. If I did a meta refresh to the affiliate url then it would still work because it would still have the correct affiliate id and a referring url. The auto click is just a work around for that. What if I had a ajax function that I wanted to be auto clicked on page load to sort a particular set of items. This function exists for reasons such as that and it shouldn't matter how it was decided to be used, it should still be supported. Commented Jul 31, 2013 at 14:23

2 Answers 2

2

Add # before the id value

$('clicked').trigger('click');

to

$('#clicked').trigger('click')
Sign up to request clarification or add additional context in comments.

2 Comments

Do you want to go to the src of iframe?
the iframe takes you to a target link...it could be done without the iframe on my end as well if needed
1

If the iframe is on your domain then you can access its contents via jquery selectors.

Otherwise you're out of luck - blocking cross domain iframe interactions is a feature of same-origin policy that exists to protect users.

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#Scripting

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.