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.
Related
How can i get the updated iframe src value after my user navigates throught the site that is inside the iframe?
I'm asking this because the src value is always the same! It don't change even if you navigate inside the iframe.
Thanks
easiest way is to use javascript to dynamicly refresh the <iframe> by setting the src to a given interval refresh rate.
Have a look at the below example
dynamicly refresh iframe without refreshing current page
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.
Here's the odd situation:
we have a piece of javascript library that is being called on our onload of aspx page.
It works everytime for us, but the clients that have low speed modems get an error, because the object is not getting initialized and the aspx page is already loaded.!!
Is there any suggestions on how to call this piece of js code?
Thanks,
make sure you have your end tags.. i have seen onLoads in the not working right when your core tags are incomplete or not properly formatted
The onload even happens when everything in the page is loaded. If you have some script that is loading from a different server (ads, statistics), the onload event won't fire until those are loaded also. If their server is having problems, your onload may never fire at all, or after several minutes when the browser gives up waiting.
Instead of using onload you could put your code in a script tag as early as possible in the page, i.e. after the last element that the script needs.
If you have some external script that doesn't need a specific place in the page (statistics for example), you can move it to the bottom of the page to minimise the risk of interference with the rest of the page.
With JQuery you can call your functions with ready event :
$(document).ready(function() {
// call your functions here
});
The event will be called when the DOM is loaded.
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.
I have a user control that is cached and as part of this control, javascript for loading a swfobject is written to the page. I've tried using ClientScript.RegisterStartupScript to write the javascript to the page, however, when rendered from the cache, the javascript is no longer included. This means the swfobject is not loaded.
Currently I'm writing the script into part of the control's div.InnerHTML, which works, but is there a better way?
No, as far as I know there is no better way.
You can use a Literal or a PlaceHolder instead of a div to put the code in, so that you don't have the extra div, but other than that it can't really be improved. If you want to cache the control, all that it does has to be included in what it renders to the page. When the controls is rendered from the cache the code behind is not executed, so it can't have any side effects outside of the control itself.