Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

populate iframe src with variables dynamically

Posted on 2014-01-16
2
Medium Priority
?
222 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 83

Accepted Solution

by:
leakim971 earned 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…
Suggested Courses

916 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