Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


populate iframe src with variables dynamically

Posted on 2014-01-16
Medium Priority
Last Modified: 2014-02-12

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="[replace_with_var1]&param2=[replace_with_var2]"></iframe>

Open in new window

What is the best way to achieve this using javascript?

Question by:Al4ddin2
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 20

Expert Comment

by:chaitu chaitu
ID: 39784934
<iframe id="ifrm" src=""+paramvalue1+"&param2="+paramvalue2></iframe>
LVL 82

Accepted Solution

leakim971 earned 2000 total points
ID: 39784942
window.onload = function() {

var var1 = encodeURIComponent( capture1 );
var var2 = encodeURIComponent( capture2 );
var iframe = document.createElement("iframe");
iframe.src = "" + var1 + "&param2=" + var2;

<div id="iframe-container"><div>

Open in new window


Featured Post

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
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…

670 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