Solved

populate iframe src with variables dynamically

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…

911 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

19 Experts available now in Live!

Get 1:1 Help Now