2

Please see below 2 HTML pages, I have 1 page inside iFrame call other page. what I exactly need, I want in "iframe.html" you can see text field. when I write something in that input box, real time that value should take inside href=""

Note : iframe.html page is pure html page. I can't use jquery inside that page. I have to access that page from index.html page.

I have tried some jquery code, but only I wrote function.

this is index.html page.

<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
</head>
<body>
    <iframe src="iframe.html" id="myframe"></iframe>

    <script type="text/javascript">
    $($("#myframe").contents().find('body')).on("click", 'a[href="#editable-link"]', function(e) {

    });
    </script>
</body>
</html>

And this is "iframe.html" page.

<html>
<head>
    <input type="text" placeholder="Enter URL">
    <a href="" id="editable-link">Read More</a>
</body>
</html>

can anyone help me to resolve this problem. it will very helpful. thanks in advance.

pet4 RX
  • 61
  • 5
  • possible duplicate of [jQuery/JavaScript: accessing contents of an iframe](http://stackoverflow.com/questions/364952/jquery-javascript-accessing-contents-of-an-iframe) – Josh May 23 '15 at 17:07
  • Hi, But still I am confuse how to do it. – pet4 RX May 23 '15 at 17:15

1 Answers1

1

Try

$('#myframe').load(function(){
  $('#myframe').contents().find('input').bind('input',function(e) {
      var url = $('#myframe').contents().find('input').val();
      $('#myframe').contents().find('#editable-link').prop('href',url);
   });
});
Josh
  • 334
  • 1
  • 17
  • Hi, but how can I real time fill it when I write something in text field. I am stop in that point. – pet4 RX May 23 '15 at 17:30
  • Hey buddy, actually I need, when I put some URL inside input box. that URL should set as Read more link. in href=" " – pet4 RX May 23 '15 at 17:46
  • It's working well buddy. you are a great developer. unfortunately still I haven't 15 reputation to vote you. but I think some one will vote you. :) cheers! – pet4 RX May 24 '15 at 04:08
  • @pet4RX could you mark mine as the answer? I think you can do that without 15 rep. Thanks! (You can do that by clicking the check mark below the upvote/downvote arrows.) – Josh May 24 '15 at 04:38