-3

I'm trying to figure out how to pass a URL I get from a string, to an iFrame on a different html page. Here is my code so far. It successfully takes the first 10 characters in my <p></p> and appends it to the end of a specific URL(which I cannot share, sorry!) What I am trying to do is open this in an iFrame so I can have a certain back button in it. Here's my code! Thanks in advance.

<script>
    function myFunction() {
        var el = document.getElementById("info"),
            text = el.innerHTML,
            res = text.substring(0, 10);

        el.innerHTML = res;
        var url = "https://www.google.com/#q=" + res;
        window.location = url;
    }
</script>

<button href="#" onclick="myFunction()">check</button>
Matt
  • 74,352
  • 26
  • 153
  • 180
  • Do not fundamentally change your question, such that you invalidate the existing answers. It is bad form. Ask a new question instead. Please don't do this again. – Matt Jun 26 '15 at 06:21

2 Answers2

0

you can try this one:

   <html>
<head>
</head>
<body>
<button href="#" onclick="myFunction()">check</button>
<iframe id="iframe1" src=""></iframe> 
<script>
function myFunction() {
    var el = document.getElementById("info"),
        text = el.innerHTML,
        res = text.substring(0, 10);

    el.innerHTML = res;



        var url = "https://www.google.com/#q=" + res;
    document.getElementById("iframe1").src=url;


    }
</script>
</body>

</html>
Amirhossein Yari
  • 2,054
  • 3
  • 26
  • 38
0

you can use java script to open new window that contain iframe and set a "name" for that window and access to its elements. like :

<script>
    function myFunction()
   {
    var myWindow = window.open("page2", "MsgWindow", "width=200, height=100");
    myWindow.document.document.getElementById("iframe1").src=url;
   }
</script>
Amirhossein Yari
  • 2,054
  • 3
  • 26
  • 38