simulate click on a specific place in page - javascript

I have a little problem with simulating a click with javascript.
I'm aware of the .click() method but the click must be on a prezi loaded (flash) so don't really have a html element to use.
What I have instead are the exactly coordinates of the place I want to simulate click on. Is there any way I can do that?
The click must activate a flash element. (A play button)
Note: There is a similar question around that have an answer witch require swf control. I don't have that so that method is not applicable.
One other quick question... what happens if I simulate a click on an element that has display: none. It click on the elements "under" it? (as a normal click would do; and yes I know this sounds funny but I don't know how to explain it otherwise). If yes I was thinking of making a position absolute div, put it on top of flash and use .click(). The problem is that i have a feeling that the click won't be applied on flash.
This is somehow a combination of javascript simulate mouse click on specific position and mouse click somewhere else on page (not on a specific div).

Make a transparent gif and position it absolute in your page wherever you need, then simulate a click on it.
I use this technique on some flash ads because I don't want to open links using JavaScript (since some users can be prompted with a question if they wan't or not to open a new page on click).

Related

How to prevent hashchange scroll in JavaScript?

I am trying to create an effect in an HTML page whereby a link with href='#section1' when clicked, changes the URL in the address bar of the browser AND scrolls to the element #section1 smoothly.
The problem is that, as far as I have been able to test, I could accomplish only one thing. Either I could scroll to #section1 smoothly using the scrollIntoView() method or I could change the address bar of the browser (which happens automatically when a link with href='#section1' is clicked.
Is there any way to accomplish both of these things?
Another thing I have tested is explained as follows:
I prevented the default action of clicking the anchor having href='#section1' using e.preventDefault() method of the click event and then called scrollIntoView() on the element. Then I manually changed the URL on the address bar using location.hash, but doing this last thing nonetheless caused the snappy scroll jump (before the browser could smoothly scroll the element into view) which I don't want.
Is there any solution to this? Or that I have to go with only one thing out of the two?

It is possible to detect a click on an ad loaded via iframe?

Having ads loaded via iframe, it is possible to detect a click with the left mouse button? A normal click?
I thought of another question, I saw a code that worked for me but it is not secure, since it monitors the activeElement, and has a flaw in it, if the user clicks with the right mouse button, the function triggers TRUE and triggers the alert.
capture click on div surrounding an iframe
If the advertisement is located on a different domain it is impossible because of security.
What you could attempt to do however, is to have a transparent element over the advertisement and detect the click there.
Then you would hide the element, and wait for the user to click a second time shrugging off the first click. If the user is actually interested in clicking the banner they will click a second time (when your transparent invisible element is gone).
Update
Have a look at this: HTML "overlay" which allows clicks to fall through to elements behind it
Apparently you can allow click through with pointer-events css.

Change page with mouse drag event

I was wondering if it's possible to change a html page on a mouse drag event. I'm trying to allow a user to click and drag a white box to the left to change the page. The link to the project is here:
URL: http://davidpottrell.co.uk/library/phone/solent.html
As you can see, I'm trying to replicate how a mobile phone works. I've got the transitions close to correct. I'm now trying to create this mouse drag event.
If it is possible, does anyone know a resources or a tutorial as to how to accomplish the end result?
How about HTML5's History API? It allows to to change the current address without reloading the page.
So one way to do that might be to let AJAX fetch the contents of the next page, place it in the current page, then maybe a page slide transition or something, and then use History API to change the address.
Here's an article from Nettuts+ about it: http://net.tutsplus.com/tutorials/html-css-techniques/a-first-look-at-the-history-api/

Intercept click on content in an iframe

I have an iframe that references an external URL that serves up pages that contain Flash adverts.
I need to track how often a customer clicks on one of those adverts.
The approach I am taking is to render a div element over the iframe. This allows me to intercept the click event, however I need to pass that click down to the iframe. Is this possible using JavaScript?
No, it's not possible. You can't simulate a real click in javascript, you can only fire click events.
I do not think that it is possible as well
But, assuming that the clicks redirect the user to the site of the advert, you could intercept the user click using redirections. Change the link to some script on your own server with some unique advert id. Register the click and redirect the user to the advertisement page.
Another possibility is to use this technique to load the contents of the iframe, so you known the amount of customers viewed the advertisement. But this of course might be an advertisement scheme your advertisement customer does not like/want.
You can't pass the click through by any legitimate means, and you'll run up against cross-domain problems if you tried to fake it in anyway. And I would definitely stay away from anything that looks like a clickjacking solution - it's bound to stop working (and feels evil too).
You may be able to hack something, depending on how accurate it has to be. This would involve tracking the sequence of events happening when user has put their mouse into the banner area and then left the page (inferring that they clicked on the ad). You'll miss some, and you may catch some false positives too.
It would work something like:
Leave the covering div in place
onMouseOver, hide the div and set an
onbeforeunload event handler that
registers a "click" through an AJAX post (or similar)
when the mouse moves out of the banner area it means they didn't click the ad, so show the div again and remove the event handler
I'd guesstimate you'd get about 80-90% accuracy, but you're going to have to test on a lot of browsers. It's also assuming the ad loads into the same window and not a new one. If it loads into a new one then I think it's going to be even harder.

IE not firing (window|document).onclick event when clicking on a child iFrame

I've got a simple dropdown menu that I want to hide whenever you click anywhere on the page (not on the menu). This works fine in FF and IE until you add iFrames into the page. The menu doesn't hide in IE when you click on the iFrame. Works fine in FireFox.
I tried using document.onclick and window.onclick.
Any ideas?
Edit:
I would prefer not to have to add anything to the iframe. The page is dynamic, and different iframes could be loaded after the menu has already been created. It would be a hassle/undesirable to have to constantly watch for new iFrames and attach events to them.
Yes I am aware of jQuery.live, but we don't use jQuery.
I assume this behaviour is possible since it works on FireFox, I just feel as though I may just be attaching the listener to the wrong event type or the wrong element.
On the parent page, you can search for iFrames in the page and add an onfocus event for them. That event will be fired when the user clicks within the frame.
An alternative would be to have the drop-down menu disappear after a set period of time has elapsed since the mouse or focus was on it rather than requiring a click to dismiss it.
click events bubble up to the owner window and no further. If you want the parent window to find out about clicks on the content inside another frame, you must catch events on its window/document (or have the child document catch clicks and inform its parent document). Yes, it will be a hassle, and jQuery live wouldn't work anyway since it relies on event bubbling.
Alternative approach: when you open a dropdown, also open a transparent ‘shade’ div behind it (but in front of everything else on the page including the iframes), and catch clicks on the shade to close the dropdown.

Categories

Resources