Is it possible to click on image on page load or right after it's loading?
thanks!
Is it possible to click on image on page load or right after it's loading?
thanks!
What?? JavaScript doesn't control the mouse... Do you mean give focus to an image? I don't know that images take focus...?
I don't really care about the mouse
I have an image that:
I want it t happen also on page loadPHP Code:onmousedown="myCommand('wan', event, 'gold')"
By the way, it's considered "best practice" to assign event-handlers in the JS (functionality) rather than the HTML (layout).Code:document.getElementById('your_image').onmousedown();
EDIT: But the event will be null because you can't make your own event.
Thank you, but I guess it is not working on page load because the image wasn't upload yet.
Is there a way to do it after the page load?
by the way this is the code I used:
PHP Code:window.onload=function(){
document.getElementById('righton').onmousedown();
}
Odd... I think that should be after the page has loaded. Images have an 'onload' handler too, but of course the JS can't get to it before the image has loaded. So try this:Code:<img id="righton" onmousedown="foo('bar');" onload="this.onmousedown();">
Thank you again!
I just don't get why steel it is not working on my specific page.
I'll try to edit it a bit..
What's your page look like? If it's online, can I have the URL?
I just tested it and now understand why the image wasn't loaded when the page was: The browser has to wait on them because they take so long and having the text ASAP is more important than having everything at the same time.
What?<img id="righton" onmousedown="foo('bar');" onload="this.onmousedown();">
Just use the onload even handler...
Code:<script type="text/javascript"> window.onload = function() { foo('bar'); }; </script>
- Mike
The way I understand it, the function that should be called won't work until the image is loaded. But it's a good idea to verify such an assumption.
Bookmarks