DIV behave like an IFRAME & load url using ajax for a web application having many forms/web pages loading each form/webpages dynamically
A div can't behave exactly like an IFrame - An IFrame has it's own javascript environment, but a div shares the environment with the parent window.
However, you can make an ajax request to a url, and insert the response into a div.
I suggest using jQuery, they have a simple function $.get(url) for this.
Related
I have an iframe within div
<div>
<iframe pageB>
</div>
on button click in iframe, redirected to a different page A - I have a jquery to hide the div on page load of A - so this part of jquery is not working - normal alert window on this page load works - I saw $ undefined - included jquery exclusively on pageA but still undefined error has gone but jquery does not work - can any body shed some light on this? doesnt jquery work in this redirection scenario.
If the IFRAME is on a different domain than the DIV this will not work due to security restrictions.
Instead of an IFRAME you could try using jQuery.load() to put the content into your div, and then hide the DIV as a part of the callback to load(). This will only require jQuery to be loaded on your main page.
I am trying to set iframe height onload , here is example
http://jsfiddle.net/hN6z3/1/
It works only when the site has loaded already but I need it to be set before it loads.
The only way you can set the height before the page loads is to do it from your server side script or in the straight HTML/CSS. If you use JavaScript, it will require some of the page to be loaded before it will run. You can't calculate the height in JavaScript until the page is actually loaded otherwise it will be less than what you expect.
My page loads an IFRAME with content from another domain (and I don't have control over the content) that contains links with target="_top" attribute. My page gets completely replaced once the user clicks on one of these links. Since my page is a stateful web application it would confuse the user.
Is there a way/trick to stop those IFRAME links to do so? They should either (visually) load within the IFRAME or open in a new window.
I don't want to proxy the IFRAME using a server script and alter the HTML code since this would block any user cookies for the foreign domain.
Perhaps some special trick like nested IFRAMEs or whatever could do this?
After googling a lot I have tried various ways to get innnerHTML of an iframe but none is working at least in Chrome 7.0 and neither in Firefox 3.6
Basically I am implementing a file uploader using iframe within a form and with the target of the form set to the iframe so that the response from server gets added to the iframe. Then I registered an eventHandler for "load" event which is where I want to check the response for which I require the innerHTML of the iframe.
Following are the various ways I have tried to get the document of the iframe window from within the onload eventHandler but it is always undefined
window.frames[0].contentWindow.document
window.frames[0].document
window.frames[0].contentDocument
document.getElementById('iframe_id').contentWindow.document
I am using the 0 index as there is only one iframe in the main window
Also the response from the server does gets displayed inside the iframe and the event handler is also getting called
Can someone please help as to what is the right way to get innerHTML of iframe which works in most browsers like FireFox 3.0+ and IE6.0+ and Chrome
Perhaps this is overkill, but I would use a div and call the jQuery function load on it. It's not exactly an iframe, but it should work all the same as well as allow you to call $('div').html() and get the exact contents of the page as well.
I have an ASP.Net page containing an IFrame. In the IFrame I load a html document. When the user clicks on a hyperlink in the content of the IFrame, I would need a callback to be called in the code-behind class of the ASP.Net page.
I guess that I need Ajax to do this but I'm not exactly sure about what I need to do. Could you give me some pointers?
By the way I'm fairly new to ASP.Net.
Thanks
A lot of this depends on what it is you want to do specifically.
The problem you've got is that the DOM of the page in the iframe doesn't appear to be in the DOM of the calling page. All the calling page sees is the iframe tag as a closed tag, like an image tag. Some browsers will detect a click inside an iframe nested within a DIV as a click in the div so you have
<DIV id="iframediv">
<Iframe blah...>
</DIV>
and then you might be able to use jQuery or similar to detect a click inside iframediv and do stuff.
The real solution would be to try not to use an iframe as, like I said, even this solution won't necessarily pay off. I can think of at least one scenario where not using an iframe is not an option so I'll leave that be.
Other than that Willem's suggestions also seem to be sound.
Because the html document is not an aspx page it will not be able to trigger any code-behind. If you can change the page in the iframe make it an aspx page and handle the click on a LinkButton like you would do otherwise.
An other option is to change the link in the html page to call a custom aspx page that handles your needs, but that will redirect the html-page to the new aspx page.
Or indeed change the link to call a webservice through javascript (XMLHttpRequest) and let that webservice do what you wanted to do in code-behind.
Finally I ended up writing a Control Extender for the IFrame. The Control Extender gets the links contained in the IFrame via the following Javascript:
var frame = this.get_element();
var links = frame.contentWindow.document.getElementsByTagName("a");
I then simply attach an event handler that reacts to each link's onclick event. The event handler calls back the ASP.Net side via a WCF service.
Not complicated to do once you know the various technologies.