How to auto scroll down an iframe 100px every 5 secs? - javascript

I would like to know how can I scroll down an iframe 100px every 5 secs using maybe javascript. I know that there is a window.scrollTo(x,y); but how does this change to an iframe?
The iframe is an external page.
Any possibility of software to download that does this thing?

This isn't possible if you do not have control of the external page's code. browsers prevent this type of thing for security reasons. Its considered cross-domain scripting.

Its very easy using a jquery,
Lets say the id of your iframe is testframe then the code for it would be
$("#testframe").scrollTop(400).scrollLeft(400);
Now just wrap it inside an interval and put it inside.
var tick=1;
function scrolldown(tick) {
$("#testframe").scrollTop(tick*100);
}
self.setInterval("scrolldown("+(tick+1)+")",5000);
Note: Just a typo

You can use setInterval to do the scrolling every 5 seconds. the scrolling itsself can be done with this.

Is there an updated version to this method? Not finding it to actually control the content within the http://time.com">
not showing. Thats rather puzzling. So typing iframe inside an iframe makes it go invisible..

If you are building a desktop application (Windows, Linux, not quite sure), I would suggest you to find a component that is the java equivalent of the C# web browser control.
Since this control is loaded in a desktop applicaiton, you have full control over the browser loaded document (e.g. you can manipulate it, without being in a cross domain context).

Related

How to send a request using html or css (no js) when element comes into viewport

I'm currently working with AMP-html in my project, which gives me no use of my own javascript on the front-end. There are built-in components, but nothing to fire a request when a certain element scrolls into the viewport.
I was wondering if there was an html/css hack in order to fire a beacon for analytics purposes. (maybe something similar to lazy-loading an image, when the url is the request url)
Thanks!
Short of it:
As far as I know, there is no way to do scroll-linked effects, delayed image loading, or "beacons" reliably without JavaScript.
Long explanation:
Browsers will request images up front for layout and DOM purposes, even if they're outside the current view. The HTML5 spec says that when scripting is disabled browsers may obtain images synchronously or asynchronously, but if scripting is enabled it must get them immediately. The spec indicates scripting is only considered disabled if the user turned it off, the browser doesn't support it, or the current document is in a sandbox.*
* Basically iframes with a sandbox attribute that doesn't contain allow-scripts as part of the value.
An old comment on another StackOverflow question indicates there are other ways to try to prevent image loading, such as using background-image, but they're not the same across browsers and can't be triggered by scrolling alone.

How iframe can capture keyboard like flash?

I have made a JS/HTML5 game which is controlled by keyboard, I like to make it embeddable like flash games, but when I embed it inside an iframe it only capture keyboard events when iframe is focused. If user interact with other element on the page iframe will lose focus and the game will not receive events.
How can I make it always capture keyboard events from inside iframe and avoid defaults like flash games? For example using space for firing instead of scrolling, from inside iframe.
Why down vote?
This is one way to do it:
function focus()
{
var iframe = document.getElementById('iframe-element')
iframe.contentWindow.focus();
}
window.setInterval(focus, 100);
or jQuery:
$("body").click(function(){
$('#iframe-element').focus();
});
This needs to be run on the host page of course, because allowing an embedded iframe to steal focus is not in the nature of browser/webpage security.
Good luck.
This is not normally possible because of a browser security feature called the Same-Origin-Policy. 1
Basically, one page on one domain can not interact with or intercept the events of another page because it would present a security risk. Imagine opening a frame to a user's bank account and then capturing keypresses they did in that frame -- obviously that would be a Very Bad Thing (tm). It works the other way around too, the contents of a frame can not see events on the parent page unless they are on the same domain.
Now browsers do still want to allow you to interact with contents within a frame. So when you start interacting with contents of one frame, the other frame loses any awareness of what's going on.
So, after all this, you're probably still wondering how to address your problem. Here are a few good options.
Instead of loading your game in an iframe, have the user embed it into their current page instead. You could have them do this by either providing them with the code to your game and having them place it in their page, or by providing a script tag that loads code from your own server and places the game into their page.
Use Cross-Document messaging 2, A relatively new browser feature that allows pages to get around the normal Same-Origin-Policy restrictions. Basically, with Cross Document Messaging, you can run javascript on the parent page that sends events into the page within the iframe.
This is not a complete Solution but an Idea....
What about capturing all Keyboard events on the site and then decide (e.g. by checking the value of some invisible input/element within the iframe) if a game is in progress. If it is, preventDefault of the action and trigger some custom event inside the iframe and just make your game listen for the custom events too...
Actually I just found this:
Access elements of parent window from iframe
That way you could apply my solution from within the Iframe and check for clicks/keys on its parent
Regards

iframed site accessing frames outside of its own

Background:
I am trying to iframe an entire external website for a project. Some links within this external site are within even more frames. They use js to access the top window and set its location according to the href value of the link, which results in the new page loading completely outside of my iframe (which I would like to avoid).
Question:
Has anyone dealt with this/is there a way to deal with this? Ideally I would like to prevent the iframed site from accessing frames outside of its own.
Note:
As per my knowledge it is not possible but still want to have a second opinion
Thank you very much for any help or insight,
To get around the restriction for the iFrame sources, the only way you can do it by setting up a web proxy script on your website.
<iframe src="proxy.php?url=http://othersite.com/">
you should be able to find some proxy implementation on some script site.

Page behaviour modifying google chrome extension?

I really want to make google mail by default bottom posting, in other words, I want the cursor in the textarea in a reply message to move automatically to the bottom.
Is this possible with google chrome extensions?
Have you maybe any other suggestions?
Problems I'm facing:
Run the extension script when gmail is fully loaded
The target textarea is in it's own iframe, is it possible to access it?
Yes, you may use the Content Scripts feature of a Chrome extension in order to manipulate the
page a user is browsing. Your content script code will run in the context of the web page the user is browsing, and it may interact with the host page almost without limit.
Manipulating Gmail might be a bit trickier than most other pages, due to its dynamic nature. Consider using the jQuery .live() method to make it easy bind to the elements you want to manipulate.
With regard to iframes, you just have to turn on the "all_frames" option in your manifest, which "controls whether the content script runs in all frames of the matching page, or only the top frame."
(I know this question is a bit stale, but I thought maybe you'd still appreciate an answer.)
I hope that helps.

Generating dynamic content in Iframe IE 7

Is it possible to generate dynamic content inside Iframe? if yes , how ? I'm having some problems with IE, thank you
UPDATE :
I'm creating a modal window which plays video, but when I close it it remains playing in IE7 although its hidden but it firefox it stops playing as it should. So I just wanted to try with iframe, thinking maybe that will solve my problem :)
As #Aaron already noted, you can use everything you use for normal pages in your iFrame.
Noteworthy however is that the content in the iframe is an isolated page.
No code from your parent page can access anything in the iframe's page.
This is a security measure that prevents Evil People from showing you trusted pages with custom javascript hooks attached.
An iframe is just like any other HTML window, so yes, you can generate dynamic content.
To create content use the normal syntax:
var div = iframe.document.createElement("div");
Please include a description of what exact problem you face. Otherwise, we can't help much.
[EDIT] Note that the URL of the document in the iframe must contain the same domain or the Same Origin Policy will prevent the access.
As for your problem with the modal window: Are you saying that the window doesn't close? That sounds like a IE bug :/

Categories