JQuery not working on redirection - iframe

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.

Related

Is there any way when click anywhere of iframe, it will redirect the website to a new website?

I used a iframe tag to show anther website. But I want people click wherever in the iframe, they can be redirect to another website as I shown in the iframe.
I tried to use onclick event, However, I found that it will not be support because of the security issue. Does anyone know how to do it instead of using onclick.
I don't know it is a good trick or not but you can have a try with this technique
As a iframe source, set a page which is in your server and on that page create a "DIV" and under the "DIV" create one new iframe with another website url. Now set an onClick event on that "DIV" which is basically on your server page. Set an "opacity" through CSS class on that div.
<iframe src="file-in-your-server.html" ></iframe>
file-in-your-server.html
<div style=""><iframe src="http://www.google.com"></iframe></div>
Hope it works, I have not tried it yet.

load page and iframe simultaneously through javascript

I had a page(Home.aspx) containing menu on the top and another master page, with same menu on the top.
Now, when i have to move from Home page to master page, i use
window.location = 'test.aspx';
Now, when i need to move from master to main(Home) page, i need to call a function with a parameter, containing control url, which has to be loaded to the iframe in the Home page.
Can anybody suggest how can i load Home page and iframe within simultaneously using javascript.
If you don't want the user interact with the page until the iframe is loaded, you can disable the page with javascript (onLoad of the page <body onload="disablePage()">) and enable again when the Iframe is loaded (onLoad of the Iframe <iframe onload="enablePage()"... )
Here some post about disable or gray out page: CSS/JavaScript Use Div to grey out section of page

Styles missing in IFrame (Asp.Net page)

I have an Iframe that initialy doesn't apply the CSS (checked the view source and the CSS link is available) but when I click on a button (submit) it reloads the same page with correct CSS and I can see the styles.
Any intial thoughts on why it is behaving like this?
Language: ASPX.Net
Are you calling it in an iframe? Sometimes iframes (if on the same domain) can apply the styles within. Depends on how it's called. Also perhaps your headers are not set properly before you do a form submit. Do you have a URL we can see?

What is the correct way to get innerHTML of iframe

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.

DIV behave like an IFRAME & load url using ajax

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.

Resources