0

I've got something like this in my index.html

<link rel="stylesheet" href="style.css" type="text/css" />
<script src="jquery-3.2.1.min.js"></script>
<script src="jquery.js"></script>

<iframe id="main" src="https://forexample.com"></iframe>

jQuery.js code is:

$(document).ready(function(){
  $('#main').load(function(){
    $('submit').click();
  });
});

I want automatically click submit button while window page is loading.

Could you help me or give me some tips?

Best regards

Tom

Shiladitya
  • 12,003
  • 15
  • 25
  • 38
IamLow
  • 1
  • 3

2 Answers2

0

Try something like

$(document).ready(function(){
  $('#main').load(function(){
    $(this).find('input#Submit').click();
  });
});

I've used jQuery find method to get the id=submit

Assumption <input name="Submit" id="Submit" value="Sign in" class="cui-field-submit cui-field-align-right" data-action="" data-confirmation="" type="submit">

Hope this will help you.

Shiladitya
  • 12,003
  • 15
  • 25
  • 38
  • Still not working, fully code of button is: – IamLow Sep 25 '17 at 15:10
  • @IamLow `id="Submit"` and in the `JavaScript` it's `#submit` that the problem. Let me update the answer – Shiladitya Sep 25 '17 at 15:12
  • Still nothing, maybe the problem is in HTML document, maybe should i put the script href in other place? Hmmm.. When I'm in my index.html i can't see the code of website in iframe. What do u think about that? – IamLow Sep 25 '17 at 15:17
  • Try `$(this).contents().find('input#Submit').click();` – Shiladitya Sep 25 '17 at 15:19
  • Still nothing. Maybe it would be easier to make some scripts in node.js or php to do different operations. I need to log in on one website by clicking submit, copy url adress, paste it in another website and click another one button. – IamLow Sep 25 '17 at 15:23
0

Try this:

$(document).ready(function(){
  $('#main').load(function(){
    var document = $(this).contents(); // To fetch contents within iframe
    document.find('#submit').click();
  });
});
Abhi
  • 4,123
  • 6
  • 45
  • 77
  • Nothing, maybe something is blocking actions like this on website in iframe.. Some filters, idk. – IamLow Sep 25 '17 at 15:28
  • Then I think you are facing **cross origin error**, something like: "Failed to ... Blocked a frame with origin "http://xxxx from accessing a cross-origin frame. " – Abhi Sep 25 '17 at 15:29