Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
Here is the code of iframe,

XML
<div id="map_canvas">
            <iframe width="100%" height="380" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/?ie=UTF8&amp;t=m&amp;ll=37.09024,-95.712891&amp;spn=26.535573,37.353516&amp;z=4&amp;output=embed"></iframe>
        </div>



here in this i want pass src's value dynamically
How is it possible?
Posted
Updated 1-Oct-20 7:52am

Hi Friend,
As per I think, it is a simple javascript which can do it for you. For example (I have not tested it, it may require some debugging)
I am using jQuery of this example.

JavaScript
$(document).ready(function(){
  var url;//You can get this url dynamically from an ajax request or from a form etc
  
  // To Do : A function to populate url with a valid url from any method you prefer.
 
  // Set an ID for the iframe. Let us give that an id of myframe
  $('#myframe').attr("src", url);
})


Here's an answer without jQuery
JavaScript
window.onload = function()
{
  var url; //You can get this url dynamically from an ajax request or from a form etc
  
  // To Do : A function to populate url with a valid url from any method you prefer.
 
  // Set an ID for the iframe. Let us give that an id of myframe
  document.getElementById("myframe").setAttribute("src", url);
}


I guess, this simple code will help you..
 
Share this answer
 
v2
Thanks for your valuable reply,
i do with this but now i got one more problem

i got this source from database,

https://maps.google.nl/maps?q=florijn+34+dronten&amp;ie=UTF8&amp;hq=&amp;hnear=Florijn+34,+8253+DM+Dronten,+Flevoland&amp;ll=52.536417,5.708256&amp;spn=0.008719,0.026157&amp;t=m&amp;z=14&amp;output=embed[^]

which is same as google map link ,but when i assign this value into iframe and run my page in mozila and chrome but map isnot shown i found that source of iframe is changed as runtime of page

https://maps.google.nl/maps?q=florijn+34+dronten&amp;amp;ie=UTF8&amp;amp;hq=&amp;amp;hnear=Florijn+34,+8253+DM+Dronten,+Flevoland&amp;amp;ll=52.536417,5.708256&amp;amp;spn=0.008719,0.026157&amp;amp;t=m&amp;amp;z=14&amp;amp;output=embed[^]

this src is got after run the page,i not found map can anybody give me solution for that.?
in short i found that value of src is change during runtime of my dotnet page.any reason or solution ?
 
Share this answer
 
Check this : What's the best way to reload an iframe using JavaScript?[^]


[Edit member="Tadit"]
Link text added to reflect the Article/QA title.
[/Edit]
 
Share this answer
 
v2
JavaScript
function SetPage(url)
{

document.getElementById("myframe").setAttribute("src", url);

}


HTML
<iframe id="myframe"></iframe>

<span onclick="SetPage('MyPage1.aspx')">My Page1</span>
<span onclick="SetPage('MyPage2.aspx')">My Page2</span>
<span onclick="SetPage('MyPage3.aspx')">My Page3</span>
<span onclick="SetPage('MyPage4.aspx')">My Page4</span>
 
Share this answer
 
hey all thanks for your suggestion but i got solution it's very simply,

i only use

C#
string Url = ev.google_map;
iframeid.Attributes["src"] = Server.HtmlDecode(Url);


server.htmldecode and got solution,

Thanks,
 
Share this answer
 
v2
Place this script before
<script>
    function newiframeSrc() {
	var url    = 'Your iFrame src here';
	var params = '&'+window.location.search.substr(1);
	var iframe_url = url+params;
	document.getElementById('iframe').src = iframe_url;
}

</script>


This is the iframe code in the
<iframe id="iframe" src="" style="width:450px;height:450px;overflow:scroll;" ></iframe>


You can use onload event to trigger it
<body onload="newiframeSrc()">
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900