Solved

populate iframe src with variables dynamically

Posted on 2014-01-16
2
216 Views
Last Modified: 2014-02-12
Hi,

I have a series of variables on the page which I have captured but now I need to add them into an iframe src URL.

<iframe id="ifrm" src="http://mydomain.com?param1=[replace_with_var1]&param2=[replace_with_var2]"></iframe>

Open in new window


What is the best way to achieve this using javascript?

Thanks
0
Comment
Question by:Al4ddin2
2 Comments
 
LVL 20

Expert Comment

by:chaitu chaitu
ID: 39784934
<iframe id="ifrm" src="http://mydomain.com?param1="+paramvalue1+"&param2="+paramvalue2></iframe>
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 39784942
<head>
<script>
window.onload = function() {

var var1 = encodeURIComponent( capture1 );
var var2 = encodeURIComponent( capture2 );
var iframe = document.createElement("iframe");
iframe.src = "http://mydomain.com?param1=" + var1 + "&param2=" + var2;
document.getElementById("iframe-container").appendChild(iframe);

}
</script>
</head>
<body>
<div id="iframe-container"><div>
</body>

Open in new window

0

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question