Cross Browser Automatically Click Link On Page Load with Javascript - javascript

I have a simple html page with an iframe image link. After the page loads I want the link to be clicked automatically. I need the link to be clicked instead of doing a meta refresh so thats out of the question. I searched around and It seems like FireFox does not support any methods to do so...There has to be a cross browser solution. Here is what I have so far but it wont work...why?
<script type="text/javascript">
window.onload=functionName;
$(document).ready(function(){
$('#clicked').trigger('click')
});
</script>
<div id="clicked">
<iframe src="http://mysource.com" width="40" height="10" scrolling="no" border="0" marginwidth="0" style="border:none;" frameborder="0"></iframe>
</div>

Add # before the id value
$('clicked').trigger('click');
to
$('#clicked').trigger('click')

If the iframe is on your domain then you can access its contents via jquery selectors.
Otherwise you're out of luck - blocking cross domain iframe interactions is a feature of same-origin policy that exists to protect users.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#Scripting

Related

how to close iframe if iframe page src redirects to specific url

i am using a simple iframe html code where i am embedding the jitsi meet url. now the problem is after finishing a meeting with jitsi it redirects to its close3.html page. i dont want to show this in my iframe. i want to close my iframe when it redirects to close3.html page. i have tried with sandbox. but after using sandbox camera and microphone access turns disable.
here is my iframe code
<iframe
title="Open identification process"
src="https://meet.jit.si/4b7562c798c20e3dd523b2298cad5327"
frameBorder="0"
width="600"
height="800"
allow="camera; microphone"
id="iframe"
onLoad="alert('Test');"
/>
You will face the Same Origin Policy when you try to do.
You can't access an <iframe> with different origin using JavaScript,
it would be a huge security flaw if you could do it.
Even so, you could use that method:
document.getElementById("iframe_id").contentWindow.location.href
Further Information

Iframe isn't visible on Chrome browser

I have an iframe issue with the Chrome browser. In http://bulbanner.cf has the following iframe code:
<iframe src="http://bulbanner.cf/script.html" width=468 height=60 marginwidth=0 marginheight=0 hspace=0 vspace=0 frameborder=0 scrolling="no" title="BulBanner - banner exchange"></iframe>
When you paste the code in another website, 468x60 sized banners are starting to visualize, because in the http://bulbanner.cf/script.html page has a rotator which shows random 468x60 sized banners. Shortly, something like this:
With Firefox everything is fine, but with Chrome very often the iframe doesn't work. Look the result with Chrome:
I think this is a security issue from Chrome browser, however is there any way to resolve it?
I have rights to change the iframe code or I can put some code in the http://bulbanner.cf/script.html page which is visualizing via the above mentioned iframe.
In this case the X-Frame-Origin header is generated by Google’s support page. So you can’t change that.
The website you want to make an iFrame has a .htaccess code that blocks iFrame request.
Like if you insert this code Header set X-Frame-Options DENY to your website’s .htaccess then any iFrame requests will be blocked.

Get browser URL from two level depth iframe

There is an iframe in an other iframe. I would like to get the browser's URL (in example: http://test) from the second iframe.
//browser URL: http://test <-- I need this URL
<iframe src="http://level1">
<iframe src="http://level2">
<!-- some content -->
</iframe>
</iframe>
I tried document.referrer but it gives back the first iframe's URL:
<iframe src="http://level1">
<iframe src="http://level2">
console.log(document.referrer); //It gives back http://level1
</iframe>
</iframe>
UPDATE:
The top.location.href doesn't work because there are different domains. Different the browser, the first and the second iframe domain. (our website - adserver - third-party website)
As said it is in general not possible from cross-domain iframes, but in the case of Chrome you can use window.location.ancestorOrigins that will give you the "top level url" and a list of all the domains if you are in several iframes no matter if they are cross-domain or not.

Open links in embedded google documents in the same window and not inside the iframe

I have a site with embedded google documents. The documents have links to other pages on the same site. The documents are embedded using the embed code from the google document sharing, for example
<iframe src="https://docs.google.com/document/d/1Rvul_FZYcdJEXFu8fRG5TB2cYgD-RFeiBuWbN44z5Gg/pub?embedded=true"></iframe>
I modify this slightly to
<iframe src="https://docs.google.com/document/d/1Rvul_FZYcdJEXFu8fRG5TB2cYgD-RFeiBuWbN44z5Gg/pub?embedded=true" seamless width=600 height=1000 ></iframe>
If that is all I do then clicking on the links in the document, open the link inside the iframe, this then shows an entire webpage inside the iframe.
I did a lot of research and came up with the following code:
<iframe id="google-doc-iframe" srcdoc="" style="height: 1050px; margin: 0 auto;" align="middle" frameborder="0" width="100%" height="100%" scrolling="no"></iframe>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
$(function() {
$.get("https://docs.google.com/document/d/1jcff6ihstj6aRVy_ojLir8briyW8afHyBYboZwCwUrY/pub?embedded=true", function(html) {
$("#google-doc-iframe").attr("srcdoc", html);
setTimeout(function() {
$("#google-doc-iframe").contents().find('a[href^="http://"]').attr("target", "_parent");
$("#google-doc-iframe").contents().find('a[href^="https://"]').attr("target", "_parent");
}, 1000);
});
});
</script>
This code worked fine, by using ajax to replace the link target attribute to the parent page.
Problem is that it doesn't work in IE 11. The following error is generated:
SEC7118: XMLHttpRequest for https://docs.google.com/document/d/1jcff6ihstj6aRVy_ojLir8briyW8afHyBYboZwCwUrY/pub?embedded=true required Cross Origin Resource Sharing (CORS).
I have looked for solutions to this, however my understanding of the code is limited and nothing I do seems to work.
Has anyone got any ideas for modifying my ajax script to work with CORS?

Google Views in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'

<iframe src='https://docs.google.com/viewer?url=https://docs.google.com/document/d/125CJmmlBfy7UgfYuBAmb1_HSCuyz8NV133361KTK1SE/export?format%3Dpdf&id=125CJmmlBfy7UgfYuBAmb1_HSCuyz8NV133361KTK1SE&embedded=false' frameborder='0'></iframe>
after this code I have next error
Refused to display 'https://docs.google.com/a/myrussiaonline.ru/viewer?url=https://docs.google.…ormat%3Dpdf&id=125CJmmlBfy7UgfYuBAmb1_HSCuyz8NV133361KTK1SE&embedded=false' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.
If I set
<iframe src='https://docs.google.com/viewer?url=https://docs.google.com/document/d/125CJmmlBfy7UgfYuBAmb1_HSCuyz8NV133361KTK1SE/export?format%3Dpdf&id=125CJmmlBfy7UgfYuBAmb1_HSCuyz8NV133361KTK1SE&embedded=true' frameborder='0'></iframe>
Then, all fine
Can I set &embedded=false and have correct render without error?
Thanks
The only way I've found to get the Google Docs Viewer to work in an iframe is:
<iframe src="https://docs.google.com/viewer?srcid=[YOUR_FILE'S_ID_HERE]&pid=explorer&efh=false&a=v&chrome=false&embedded=true" width="800" height="600" style="border: none;"></iframe>
Try this tutorial-
https://www.youtube.com/embed/A5SkbcId-v0
U should have your answer.
Update-
According to Google Policy, if u like to have your document viewed with a iFrame, then embedded=true should be in the URL.
Demo Code-
<iframe src='https://docs.google.com/viewer?url=https://docs.google.com/document/d/125CJmmlBfy7UgfYuBAmb1_HSCuyz8NV133361KTK1SE/export?format%3Dpdf&id=125CJmmlBfy7UgfYuBAmb1_HSCuyz8NV133361KTK1SE&embedded=true' frameborder='0'></iframe>
First you should go to your document on google drive :
click file
publish to the web
embed
publish
You will get the code of the iframe you can use it to visualize your spreadsheet without the possibility to edit it
No, you can not, this parameter is specify that source would be embedded. And the idea behind using it is to avoid clickjacking attacks

Categories