Solved

populate iframe src with variables dynamically

Posted on 2014-01-16
2
214 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

759 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now