JS Help need , fill iframe form with JS

6 replies
Hello,

i want to add text to a text box inside of iframe. bellow my code but it's not working ??

can any one help?

HTML Code:
<html >
<head>
 <script type="text/javascript">      
     function myd() {
     	
	document.getElementById('myform').document.forms('form1').text1.value = 'Hello world!';
        
   }
  
  </script>

<title>Untitled Document</title>
</head>

<body>
<input type="submit" name="Submit" value="Submit" onclick="myd()" />
 
<iframe  name="myform" src="text.php" width="100%" height="500">
</iframe>

</body>
</html>

iframe html

HTML Code:
<html>

<body>
<form id="form1" name="form1" method="post" action="">
  <input type="text" name="text1" />
</form>
</body>
</html>
#fill #form #iframe
  • Profile picture of the author rahman.warrior
    ok!! it's working like this

    HTML Code:
    <script type="text/javascript">
     function losad() {
      
    window.myform.document.getElementsByName("unam")[0].value = "some text";
    			      
       }
            </script>
    BUT it's not working when loading external URL

    any one can help?
    {{ DiscussionBoard.errors[5168089].message }}
  • Profile picture of the author eminc
    If you mean you are putting a page from another domain in the iframe and trying to access that, it won't happen . Wonder if somebody were to embed a iframe of a Bank account system and take username and password values from there in a parent site . Its called Same origin policy.

    You can read about it here : Same origin policy - Wikipedia, the free encyclopedia

    Mohit
    Signature

    The best way to predict future is to create it ― Abraham Lincoln

    {{ DiscussionBoard.errors[5168267].message }}
  • Profile picture of the author eminc
    You can see the workaroudn section of the same article in Wikipedia.

    To enable developers to, in a controlled manner, circumvent the Same Origin Policy, a number of 'hacks' such as using the Fragment Identifier, or the `window.name` property have been used to pass data between documents residing in different domains. With the HTML5 standard a method was formalized for this: the `postMessage` interface, which is only available on recent browsers. JSONP and Cross-Origin Resource Sharing can also be used to enable AJAX-like calls to other domains.[2]
    For supporting older browsers, the JavaScript library easyXDM can be used to provide a unified API for the `postMessage` interface as well as a number of hacks used to allow Cross Domain Messaging (XDM).
    Source: Same origin policy - Wikipedia, the free encyclopedia

    Mohit
    Signature

    The best way to predict future is to create it ― Abraham Lincoln

    {{ DiscussionBoard.errors[5168525].message }}
  • Profile picture of the author SeeSharp
    Hello junly,

    As the Wikipedia Article posted above already said, it's not possible to modify any object on another domain than the one you are visiting currently.
    These preventions are there to prevent what you try to do: To automatically fill CPA offers, send emails and stuff like that without a user noticing.

    I guess you are trying to autofill some CPA offer and your question refers to how other cpa autosubmit programs work.
    They are windows executables, meaning they don't use javascript which is bound to the same origin policy.

    Hope this helps you.

    Greetings
    {{ DiscussionBoard.errors[5172261].message }}
  • Profile picture of the author rockerzz
    bind a load event to the iframe and execute your code into that
    {{ DiscussionBoard.errors[5177247].message }}

Trending Topics