Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dynamically set iframe src

I have a program which will dynamically set an iframe src to load pages. I need to hook a event handler for the page completely loaded. How can i do it? Thanks!

like image 664
Dagang Avatar asked May 14 '11 09:05

Dagang


People also ask

Does the src property of an iframe can be changed using JavaScript?

To change the iframe src attribute, we will be using a select drop down menu, and a button element to activate the function that will change the src attribute. Note that this is only for example purposes, instead of using onClick you may want to consider using event handlers in an external script.

How do I change iframe content dynamically?

You can use the following to change the src attribute of the iFrame: $("#content"). attr('src', 'http://mysite.com/newpage.html');

How do I do an iframe in href?

You can embed an iframe in a page that is inside another iframe on another web page. When you set the target attribute to _parent, the link will open in the web page that is holding the iframe. In most situations with iframes, this target will open links in the same way that the _parent target does.

What is the use of SRC in iframe?

Definition and Usage. The src property sets or returns the value of the src attribute in an iframe element. The src attribute specifies the URL of the document to show in an iframe.

How do I change the iframe src attribute?

To change the iframe src attribute, we will be using a select drop down menu, and a button element to activate the function that will change the src attribute.

How to read the value of an input field in iframe?

Try this: add a hidden input field (with runat="server" attribute) and change it's value to your IFrame's src in the JavaScript. That way, you'll be able to read the field's value server-side.

How to add iframe in ASP NET application?

In this first we will create a new asp.net application and add a web page. In this webpage we will add and iframe and add server tag which Is runat=”server”. Please check the above code above highlighted piece of code. Now this iframe control is accessible on server side code of your application. Now add a new page which we will display in iframe.


2 Answers

<script type="text/javascript"> function iframeDidLoad() {     alert('Done'); }  function newSite() {     var sites = ['http://getprismatic.com',                  'http://gizmodo.com/',                  'http://lifehacker.com/']      document.getElementById('myIframe').src = sites[Math.floor(Math.random() * sites.length)]; }     </script> <input type="button" value="Change site" onClick="newSite()" /> <iframe id="myIframe" src="http://getprismatic.com/" onLoad="iframeDidLoad();"></iframe> 

Example at http://jsfiddle.net/MALuP/

like image 55
simonbs Avatar answered Oct 13 '22 10:10

simonbs


Try this:

top.document.getElementById('AppFrame').setAttribute("src",fullPath); 
like image 44
Deepika Avatar answered Oct 13 '22 12:10

Deepika