Sending url to iframe in different page

101 views Asked by At

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>
2

There are 2 answers

0
Amirhossein Yari On

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>
0
Amirhossein Yari On

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>