iFrame with DIV and Jquery is not working - javascript

I am trying to use content of other website into my website. I tried using DIV with Jquery instead of iframe tag <iframe>
My Codes :
<head>
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js?ver=1.4'></script>
<script type='text/javascript'>
$(document).ready(function (){
$('#divframe').load('http://www.example.com');
});
</script>
</head>
<body>
<div id="divframe"></div>
</body>
it returning no value and not showing the content of the example.com on my website. means the page is empty & blank.
Edited: I am looking for iframe solution without iframe, object, embed tag.
Please help me to get it fixed :)

You need to use iframe tag and attr() to do this.
NOTE : you also need to be sure that the url of the website is not protected to be loaded via 3rd party site frame of iframe like youtube.com, google.com, etc.
https://en.wikipedia.org/wiki/Framekiller
$(document).ready(function (){
$('#divframe').attr("src", "https://wikipedia.org/wiki/Main_Page");
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<iframe id="divframe" style="width:100%;height:95vh"></iframe>

Related

Open healcode link in iframe

The problem I am having is preventing a link from launching a new page and loading its href value in an iframe. The client site is using healcode a service that provides widgets to schedule fitness classes etc.Check this page When you click the signup button after the widget loads it opens a new page. What the client wants is to open that link on the same page or in a popup window. I have tried everything I can think of. I have used jQuery,fancybox, etc.
HERE IS THE CODE IM USING
screenshot.
What I think the problem is, is that my inline scripts loads before the widget scripts finish renders the the schedule html.
I know it is possible because this site uses the same widget and their signup opens the link in a overlay frame on the same page.
Please shed some light on this.
UPDATE:
<html>
<head>
<title>Test</title>
</head>
<body>
<iframe id="openViewHere" width="500px" height="500px" src="" ></iframe>
<script type="text/javascript">
healcode_widget_id = "7696499e81";
healcode_widget_name = "schedules";
healcode_widget_type = "mb";
document.write(unescape("%3Cscript src='https://www.healcode.com/javascripts/hc_widget.js' type='text/javascript'%3E%3C/script%3E"));
// Healcode Schedule Widget for Iyengar Yoga Association of Greater New York : Brooklyn Daily Class Schedule
</script>
<noscript>Please enable Javascript in order to get HealCode functionality</noscript>
<script src="https://code.jquery.com/jquery-1.11.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(".signup_now").click(function(){
var url = $(this).attr("href");
$("#openViewHere").attr("href",url);
return false;
});
</script>
</body>
</html>
Just use this code :
$( document ).ready(function(){
$("body").on('click',".signup_now",function(e){
$(this).attr("target","_self")
})
})
be aware that windows.ready() might fire , while the widget script is still adding elements dynamicaly that is why the listeners dont work , you have to access the element through already loaded parent ( e.g "body" ).

How to load jQuery from the iframe to its parent page

I have a below code in my iframe and it contain some jQuery and I want to call it from the iframe to parent page but it not working and path of the iframe is the content/test/doubleimg.html
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="https://www.example.com/content/test/base64.js"></script>
<script type="text/javascript" src="https://www.example.com/content/test/doubleimg.js"></script>
And double img contain some jQuery function which is execute onload of the page and it work fine but if i put it in iframe its not working.
And my html markup like and path of the parent file is template/category.html
<div id="Container">
-----------
-----------
<div class="Content" id="LayoutColumn2">
<iframe id="theiframe" allowtransparency="true" target="_top" src="/content/test/doubleimg.html" frameborder="0" height="0" width="0"></iframe>
</div>
</div>
So please suggest me the idea how can I use jQuery from the iframe and my jQuery is execute on the page load.
Actually I am trying to call api of the Bigcommerce but for that I need to set https and I can't set it because it not allowed in the Bigcommerce to set https in category page url
And if I am not set https then the API returns a 401 authentication error
So please help me out from this.
Something like this, if documents are in the same domain:
var iframe = document.getElementsByTagName('iframe')[0];
var jQuery = iframe.contentWindow.jQuery;
alert(jQuery);
See my jsfiddle for more information. It include other jsfiddle in iframe there I inited jQuery.
try this
window.parent.document.wirte('<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>');

how to refresh/reload only once after the page is loaded in jquery mobile

how to refresh/reload only once after the page is loaded in jquery mobile. because am using wow slider and when it is loaded the data is getting dynamically but the ui is not correctly getting once the page is refreshed it is getting. Can someone help me for this thanks.
I found this... This works for me. May be it will work for you also. Just include this script in your 'data-role="page" div' available in your mobile jquery page.
Below is test1.html:
<body>
test <!--This link redirects to test.html but you will see 'test.html#' at address bar that means you page is reloaded once -->
</body>
test.html:
<body>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript">
$(document).ready(function(){
if(location.hash != 'test1.html'){
location = 'test.html#';
}
});
</script>
</body>

Replace the content of _top window with content of iframe without reload page

Is it possible to replace the content of the browser window (_top frame) with the document loaded in an iframe, without issuing a new GET to load that document?
Something like this:
<html>
<head>
<script type="text/javascript" language="JavaScript">
$(document).ready(function() {
$("#link").click(function() {
// should present in the browser window the content of the iframe WITHOUT reload
// even preserve javascript/head code
$(document).html($("#frameDestination").html());
});
});
</script>
</head>
<body>
<a id="link" href="#">full window</a>
<iframe id="frameDestination" src="http://www.some-random-site.com" width="900px" height="500px"></iframe>
</body>
</html>
Use contents() when working with an iframe in jQuery.
$("#YourIframe").contents().find("html").html();
This is only going to work if the iframe is in the same domain as the parent.
I haven't tested cross domain, but on the same domain I have this script working:
$(document).ready(function() {
$("#link").click(function() {
var iframeBody = document.getElementById("frameDestination").contentDocument,
head = iframeBody['head'].innerHTML,
body = iframeBody['body'].innerHTML;
$('body').html( body );
$('head').html( head );
});
});
In the latest Firefox, I'm even able to set a variable in a script tag in the frame, and see that value in _top after clicking the link.

Accessing IFrame elment from external page loaded inside iFrame

I would like access the IFrame element available in the main page from the IFrame source page using JavaScript
Here is my main Page
<html>
<body>
<IFrame id="page-container" src="http://stackoverflow.com"
width="200px" height="200px">
</IFrame>
</body>
</html>
Child Page
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.js"/>
<script type="text/javascript" >
$(document).ready(function(){
var containerFrame= $('#page-container');
//var containerFrame=document.frames["page-container"];
//var containerFrame=document.frames["page-container"];
//var containerFrame=document.parent.frames["page-container"];
});
</script>
<body>
<div>some content..</div>
</body>
</html>
I am getting undefined for all my tries.
How it can be done? Is it possible?
Edit: I tried loading a cross domain page.
In IE i am getting error ' for security reason framing is not allowed' and also
domains, protocols and port must match. Can we achieve this any way?
var containerFrame = $('#page-container', window.parent.document)
This should firstly reference the parent of the window and then look for the iframe div
You need to specify the context to search for #page-container in, which in this case will be the parent window.
var containerFrame = $('#page-container', window.parent.document);

Categories