refresh iframe from a .php in a separate iframe - javascript

I have a page that is built with 7 different iframes:
<iframe id="leftframe" src="structure/leftbar.php"></iframe>
<iframe id="headerframe" src="structure/header.php"></iframe>
<iframe id="menuframe" src="structure/menu.php"></iframe>
<iframe id="timerframe" src="structure/times.php"></iframe>
<iframe id="settingsframe"></iframe>
<iframe id="contentframe" name="contentframe"></iframe>
<iframe id="chatframe" src="chat/index.php"></iframe>
I have a .php that is being run in the "contentframe". When I click a button in it, it sends a post to a .php. The .php functions properly but at the end of it, I want it to reload the leftframe frame.
I tried the suggestions on these pages:
How to refresh an IFrame using Javascript?
What's the best way to reload / refresh an iframe using JavaScript?
but neither of these seem to work.
in the .php I am trying:
?>
<script>
parent.getElementById('leftframe').location.reload();
alert("Ping");
</script>
<?php
This doesn't work either. Any suggestions?
Thanks!

Using back-end to refresh an iframe when you can do it client-side is absolutely wrong.
It works for me:
<script>
document.getElementById('leftFrame').contentWindow.location.reload();
alert('Ping');
</script>
And, yes, are you sure you need iframes?
It is definitely not a good practice. Especially, in a century of powerful JS and its frameworks and AJAX. It would be better if you updated the content of DOM element instead of refreshing iframe.

Related

using Javascript to locate an element in an Embedded web page which also in an embedded web page

I want to write a script to watch online courses automatically using Javascript. But when I want to locate an element in the html page,I find it was in an embedded web page which also in an embedded web page. I have been searching questions in Google and Baidu but I only find the way how to locate an element in an embedded web page. I also ask programmers around me but they also have no idea,oops. the following picture is the position of it("span" is the target).
<html>
<body>
<div class="main">
<iframe id="iframe" src="blala" allowfullscreen="ture" onload="clickImg()">
<html>
<body>
<div class="ans-job-icon">
<iframe src="video/blala" allowfullscreen="ture">
<html>
<body>
<span aria-hidden="true" class="vjs-icon-placeholder"></span>
</body>
</html>
</iframe>
</body>
</html>
</iframe>
</body>
</html>
Can you do me a favor? thx a lot.
Thank for all of your idea. With your advice, I finally work out this question with my friends. The solution is as
followed.
We find that “window" is one of the object in JavaScript, which can operate the element in "iframe". So you can use it to locate the tag in an embedded web page.
top
"top" is an attribute in the object window. By using the statement "window.top", you can get the top window in the web page. and then
Using the statement"window.top.iframe" to get the iframe object .
get the next iframe tag by object "document"
attribute "contentDocument" in iframe can be used to return the current document object. and then you can find the next iframe using the statement"window.top.iframe.contentDocument.getElementsByTagName('iframe')[0]"!

Get height tag html5 <embed> for jquery

I'm trying to get the height from an external page that is inside an embed tag with jQuery.
I also need to resize the embed tag when the content inside changes in height. I tried using the following code but it doesn't seem to work. What would be the best approach for this case?
HTML
<html>
<body>
<embed src="www.example.com" height="100%">
</body>
</html>
JavaScript
$('#test').height()
$('embed').height()
After some hours I solved my problem with this:
cross domain
This saved my integration from my application in asp.net with WordPress.
Thanks for everybody that tried help me.

Getting content through iFrame with jQuery

I'm loading an iframe with jquery and I would like to scrape content from the iFrame.
The content is on a diffrent domain than my own.
For some reason I keep getting the alert as "undefined".
<iframe id="myiframe" src="http://www.cnn.com" style="width:1000px; height:300px;"></iframe>
<script>
setTimeout(function() {
alert($("#myiframe").children("div").html());
},5500);
</script>
You can't do anything with iframe content if content belongs to other domain.
This is short but full answer for this question
There is no way around it but to use a proxy - but I would question whether there would be legal issues in doing so.
Read here https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS

iframe accessing child JavaScript of source

I have been trying to access a html source file through iframe. It works fine and I can see the source, but my external JavaScript file doesn't work through the iframe.
So far this is what I have for accessing the HTML file.
<iframe src="Example.html">
<p>Your browser does not support iframes.</p>
</iframe>
and then in Example.html I have:
<script src="SpinScript.js"></script>
This works if I run the HTML file in any browser, but not through the iframe
In this HTML file I have other JavaScript elements but they are just written in this document and they work fine through the iframe.
What I'm wondering is if have to re-establish where the JavaScript file is in the iframe?
Hope that all makes sense and thanks for your time.
Your parent window and iframe should be from the same source (url),
then you can use
window.frames[framename] to get window object in iframe

Javascript/Html: Load Html into FrameSet with onunload event

Explanation of problem in full below, you could probably just skip to the code at the bottom if you want.
What happened is a impatient client wanted his swf banners converted to html5 without having to actually code them from scratch. So i utilized Google's new tool, Swiffy. I then tried to place this new generated html5 page in the header of the clients wordpress site. I have gotten it to load as an iframe but the problem that I am encountering is when you click on a link on the loaded html5 page, it just loads the linked page in the iframe, not the parent page/window (which is to be expected). I tried a bunch of other methods, and tried changing the AS2 links in the .fla as well but no luck. I am guessing Swiffy can not read every AS2 code, and so it has been ignoring my "_blank", "_parent" when I use getURL. Anyway, I have been trying to get it so when the iframe unloads to go to the linked page, it uses Java to just open the link on the parent page. But iframes cant use the onunload event, but I am pretty sure framesets can. So this is the code I was trying and it doesnt work.
<frameset rows="100%" onunload="window.open('http://www.goaefis.com/about-aefis/what-is-aefis/','_parent');">
<frame src="www.goaefis.com/banner_Test.html" frameborder="0" scrolling="no" />
</frameset>
Any help will be super appreciated.
try to use the "target" on your frames.
Here's a example:
http://www.w3.org/TR/html4/present/frames.html

Categories