Refresh iframe? - javascript

I have an iframe on my page where you can checkout my latest web development pages, and so on. Is it possible to refresh it with regular JavaScript or jQuery?
<iframe src="projektit" style="width:100%; height:400px; border:none;" id="iframe"></iframe>
I'm thinking about something like this.
$.ajax({
url: "../",
success: function (data) {
$("#iframe").html(data);
}
});
Any ideas?

<iframe id="homepage" frameborder="1" width="400" height="300" src="http://jbcurtin.com/"></frame>
<script>
var frame=$("#homepage")
frame.attr('src',frame.attr('src'))
// None jquery:
var frame=document.getElementById('homepage')
frame.src=frame.src;
</script>
http://jsfiddle.net/ekpAm/

jsFiddle
To refresh an iframe I would suggest just changing the src value.
Changing the src value will trigger the iframe to refresh.
$('#iframe').prop('src', url);
If you notice it's not refreshing, you could always attach a bogus query string value to the end of the url in the case of it being cached.
var q = new Date(); // use current date obj as query string value
$('#iframe').prop('src', url + '?q=' + q.getTime());

Related

Node JS Get all iframes from url

I have a static webpage which I can't change and I need to get all iframes on this page. The iframes have no id's or name. They look like this
<iframe height="584" width="630" src="someurl" scrolling="auto" noresize="" frameborder="0"></iframe>
So, I can get the "main page" content with the module request but I don't know how to loop through it and find all iframe elements and their sources!
Hope you can help,
dunklesToast
The node module called cheerio is a node-like jQuery alternative. You can load your content of the "main page" and then get all the iframes like this:
var cheerio = require('cheerio')
var $ = cheerio.load(mainPageContent);
$('iframe').each(function(index, element) {
var url = $(element).attr('src'); // --> Get the URL of the iframe
// Do something with the URL of the iframe here
});

iFrame URL parameter to an in Wordpress?

I have a page which has an iframe embed of an external page. I want to find zip code
Here is my iframe:
<iframe src="http://mortgagerates.icanbuy.com/?zip=" width="1020" height="1200">
http://mortgagerates.icanbuy.com/?zip=10458 (Main Site )
But i want i frame and my browser url same below:
http://www.mysite.com/?zip=10458 (I want something like that)
Is this possible in wordpress? how?
Please check it.. I hope work it...
<iframe src="http://mortgagerates.icanbuy.com/?zip" width="1020" height="1200" class="iframe-wrapper">
And add this jQuery. Thats It!
<script type="text/javascript">
$(function() {
var search = window.location.search;
search = search.replace("?","&");
$(".iframe-wrapper").attr("src", $(".iframe-wrapper").attr("src")+search);
});
</script>
This is ajax page. you want to use ajax.
http://mortgagerates.icanbuy.com/ajax/rates-search?callback=jQuery17209362620610679678_1385958692723&source=1&results_count=0&period=PERIOD_FIXED_30YEARS&state=33&property_type=34&occupancy=49&fico=740&points=1.5&currently_working=Yes&property_interested=Yes&show_fha=0&cashout=0&city=10458&valoans=0&militaryaff=1&hadvabefore=0&rate_lock=99&loan=200000&transaction=54&ltv=80&cltv=80&DO_UPDATE_WRITE=0&id=d4ea9f8db0477778&external=0&_=1385958692873
you need to pass your zipcode into city=10458. its return json encoded format. you simply parse this into your design.

how do i load a view(cshtml) into an iframe?

I'm trying to load a view into an iframe in another(parent) view using javascript and razor.
I'v tried setting the iframe's src to this
var url = '#Url.Action("myaction", "MyController")';
and this:
var url = '#Href("~/myform.cshtml")';
without success.
Thanks
Thanks
If you are using razor engine.
<iframe src = '#Url.Action("myaction", "myController")' width = "100%"
height="1000" frameBorder="0"></iframe>
Set the 'src' attribute of the iframe to the action's url.
Example:
<iframe src ='home/index'></iframe>
Make sure you replace the URL within the src attribute to the URL of the action.
An alternative way in Razor:
<iframe src ='#Url.Action("action name")'></iframe>

How do I set the src to an iframe with jQuery?

My iFrame looks like this:
<iframe id="iframe" name="iframe1" frameborder="0" src=""></iframe>
And my script looks like this:
<script type="text/javascript">
$(document).ready(function() {
$('#iframe').attr('src',http://google.com);
})
</script>
I've also tried putting quotes around the url:
<script type="text/javascript">
$(document).ready(function() {
$('#iframe').attr('src','http://google.com');
})
</script>
But neither is working.
What am I missing?
If you look at the browser's error console, you'll see the real problem:
Refused to display 'https://www.google.com/' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.
Google doesn't let you do that.
<script type="text/javascript">
$(document).ready(function() {
$('#iframe').attr('src', 'http://google.com');
})
</script>
Quotes missing on the url.
You're not allowed to load www.google.com in an iFrame. Try it with another url.
Load denied by X-Frame-Options: https://www.google.com/ does not permit cross-origin framing.
$("#iframe").attr("src","your url");
this will work fine.
Just call the function with Iframe name and desired url
function loadIframe(iframeName, url) {
var $iframe = $('#' + iframeName);
if ( $iframe.length ) {
$iframe.attr('src',url);
return false;
}
return true;
}
Ex:
loadIframe("iframe1","http://yahoo.com");

Open iframe page in parent frame (javascript)

I'm sure someone in the know has a solution to this problem I'm facing? I have a site with Index.html which contains an Iframe. In this iframe, all pages of the site are shown...Home.html..Info.html...Contact.html..etc.
I'd like a javascript function so that when you open Home.html via the google sitemap for example, it shows up in the parent frame in Index.html. The function I currently have in the head section of each child page is:
<script>
if (parent.location.href == self.location.href){
window.location.href = 'index.html'
}
</script>
Although this works, it doesn't remember the child page and opens the Index page with the default iframe page...Home.html as the iframe is coded like this:
<iframe id="iframe" src="home.html" allowTransparency="true" id="iframeID" name="iframeID" width="100" height="100" scrolling="no" frameborder="no">
</iframe>
Has anybody a solution to this problem, as I've searched everywhere? Thanks.
Try to set location.href with a query string, i.e.:
// .getAttribute so we don't get the absolute URL
var src = document.getElementById("iframe").getAttribute("src");
if (parent.location.href === self.location.href)
location.href = "index.html?" + escape(src);
In index.html create a check for query strings and set the iframe source accordingly:
if (location.search)
document.getElementById("iframe").src =
unescape(location.search.substring(1));

Categories

Resources