1
<iframe id="myFrame" runat="server" name="main" width="100%" src="http://www.somewebpage.com/" />

This is simple iFrame I put on my webpage. After I click on couple of buttons on that website, iframe source remains the same. But I want to be able to retrieve the changed source every time I click on buttons, links etc...

How can I achieve this?

Edit: This is the screenshot of my work. When I click on "Git" button, webpage loads on the iFrame. However, when I surf on the website, I want textbox to be updated to the source of the iFrame.

Cute Bear
  • 3,223
  • 13
  • 44
  • 69
  • where are the click buttons ? on the main page, or on the iframe page, and what is not change the main page or the iframe ? Your question is not clear, is the 2 sites the same ? – Aristos Feb 18 '12 at 13:20
  • http://dl.dropbox.com/u/38860715/iframe.png Here just look at the screenshot I captured. When I click on "Git" button, webpage loads on the iFrame. However, when I surf on the website, I want textbox to be updated to the source of the iFrame. – Cute Bear Feb 18 '12 at 13:28
  • Still do not understand what button you press and what you expect to see. – Aristos Feb 18 '12 at 13:32
  • can you show here the code behind of the key pressed ? – Aristos Feb 18 '12 at 13:33
  • Just imagine a web browser. When you type google.com on the adress bar and search something on google, address bar changes dynamically. In my project Textbox is my address bar, and "Git" button is my "Go" button that loads the webpage on the iframe. – Cute Bear Feb 18 '12 at 13:38
  • so I want my textbox to be updated based on what I do on that website. In the screenshot, that webpage is American School Directory. – Cute Bear Feb 18 '12 at 13:39
  • at first iframe source was http://www.asd.com but then after clicking on buttons and links on American School Directory, source changed to http://www.asd.com/asd/typicalschool.htm Howevery I want the iframe source to be set to textbox.Text which you can see it on my screenshot (There is only one textbox). – Cute Bear Feb 18 '12 at 13:51

1 Answers1

0

Ok, here is an idea that I test it now and its work. You change the input box after the iframe loads using the onload event of the iframe

<script>
function HasChange(me)
{
    document.getElementById("WhereIamId").value = 
                 document.getElementById("WhatIShowID").src;        
    return false;
}
</script>

and the html

<input type="text" id="WhereIamId" value="" />
<iframe src="page1.aspx" onload="return HasChange(this);" id="WhatIShowID" ></iframe>

You can use also the document.getElementById("<%=myFrame.ClientID>") to get the rendered id. After your iframe loads you update the text box with the current url.

Aristos
  • 66,005
  • 16
  • 114
  • 150
  • When I build the page, it says: **Error 3 Identifier expected; 'return' is a keyword** for this line `` – Cute Bear Feb 18 '12 at 14:42
  • @MehmetBudak Ether remove the runat=server, ether add this attribute on code behind. I have test it and work. – Aristos Feb 18 '12 at 15:02
  • I think, runat=server attribute should remain, but adding the action shall be completed at this way; defining the attribute adition by .cs file with TextBox1.Attributes.Add("onchange","HasChange(me);"); – Cute Bear Feb 18 '12 at 16:49
  • The solution you provided didn't work. All it does is getting iframes src which is assigned at startup to the web browsers address bar. And it doesnt update the textbox at all. But nevermind Ill you something else to achieve the problem. Since you are the only person you tried to help me, I just want to mark your answer as correct answer to show you my appreciation! Thank you so much for your help @Aristos! – Cute Bear Feb 19 '12 at 13:59
  • @MehmetBudak Thank you for what you say, but I tell you one more time, it work for me, I can send you the source code to see it. I do not test it for all browsers but it work. The other idea that I think is a timer that update every second the text bar. Do you won to send you the source code to see it ? – Aristos Feb 19 '12 at 15:04
  • Thank you friend. The reason i gave up on this quest was being not able to capture an iFrame screenshot properly so I started up another topic to look for the solution! http://stackoverflow.com/questions/9362620/take-a-screenshot-of-an-iframe – Cute Bear Feb 20 '12 at 15:16