Solved

populate iframe src with variables dynamically

Posted on 2014-01-16
2
219 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
[X]
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
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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

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…
Suggested Courses

617 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