473,396 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How do I use SetTimeOut inline?

QA
<img src=http://xxx.com/yyy.jpg
onmouseover="settimeout(\"document.location='http://www.google.com'\"),
2000">

I want to have a 2 seconds delay before it is directed to an URL when the
mouse is over the image.

However, it seems that setTimtOut does not like parameters in the function
part.
Jul 23 '05 #1
5 8028
"QA" <QA@alexa.com> writes:
<img src=http://xxx.com/yyy.jpg
onmouseover="settimeout(\"document.location='http://www.google.com'\"),
2000">
There are quite a lot of errors in these lines.

First of all, the src attribute value must be quoted.

In the "onmouseover" attribute, since it is quoted (as it should be) with
"'s, you cannot use "'s inside the value. Using Javascript escapes doesn't
make a difference. You can either use &quot; instead of \" or switch
to using single quotes.

The function is called "setTimeout", with that exact capitalization.

The second parameter (2000) is not really a paremeter, since it is outside
the parentheses.

Try:

<img src="http://xxx.com/yyy.jpg"
onmouseover=
"setTimeout('document.location=\'http://www.google.com/\'',2000);">

or
<img src="http://xxx.com/yyy.jpg"
onmouseover=
"setTimeout(&quot;document.location='http://www.google.com/'&quot;,2000);">
I want to have a 2 seconds delay before it is directed to an URL when the
mouse is over the image.
What's wrong with clicking, now? :)
However, it seems that setTimtOut does not like parameters in the function
part.


Sure it does. It just wants two of them.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #2
QA
>
Try:

<img src="http://xxx.com/yyy.jpg"
onmouseover=
"setTimeout('document.location=\'http://www.google.com/\'',2000);">

or
<img src="http://xxx.com/yyy.jpg"
onmouseover=
"setTimeout(&quot;document.location='http://www.google.com/'&quot;,2000);">
I want to have a 2 seconds delay before it is directed to an URL when the mouse is over the image.


http://www.infimum.dk/HTML/rasterTriangleDOM.html
Thanks JS master!!!!

I got another question: How do I open the window in a NEW window? I don't
want to use window.open as it will be blocked as popup. I tried this:

<img src="http://xxx.com/yyy.jpg"
onmouseover=
"setTimeout('document.location=\'http://www.google.com/\'',2000);"
target=_blank>
and this
<a href="#" target=_blank>
<img src="http://xxx.com/yyy.jpg"
onmouseover=
"setTimeout('document.location=\'http://www.google.com/\'',2000);">
</a>

I hope to use target="somename", does this automatically register somename
as a frame/object? or I have to declare it first or use somename before i
call it?

Jul 23 '05 #3
"QA" <QA@alexa.com> writes:
I got another question: How do I open the window in a NEW window? I don't
want to use window.open as it will be blocked as popup.
You can expect any other way to open a window as a result of a mouseover,
to also be blocked, if there is a popup blocker at all.

Some blockers block all new windows, others only those not caused by
a user input (typically a click, not simply a mouseover).
I tried this:

<img src="http://xxx.com/yyy.jpg"
onmouseover=
"setTimeout('document.location=\'http://www.google.com/\'',2000);"
target=_blank>
Img elements doesn't have a target attribute, so that won't help.
and this
<a href="#" target=_blank>
<img src="http://xxx.com/yyy.jpg"
onmouseover=
"setTimeout('document.location=\'http://www.google.com/\'',2000);">
Changing the "document.location" (which, btw, should probably be
"window.location" for maximum compatability) has nothing to do with the
link that happens to be around the image. So, again, a no go.
I hope to use target="somename", does this automatically register somename
as a frame/object?
If you click on a link with a target attribute (or otherwise open a
link in a named target), a window is created with that name if it
doesn't exist already. Nothing happens before you click, though.
or I have to declare it first or use somename before i call it?


No declaration is necessary.

Ok, one solution that doesn't use window.open, and tries to open
in a new window:
---
<a id="hiddenLink" name="hiddenLink" href="http://www.google.com&"
target="someTarget" style="display:none"></a>
<img src="..."
onmouseover="setTimeout('document.links.hiddenLink .click()',2000);">
---
A good popup blocker will stop it anyway, so good luck :)

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #4
"QA" <QA@alexa.com> wrote in message news:<B2******************@news01.bloor.is.net.cab le.rogers.com>...
<img src=http://xxx.com/yyy.jpg
onmouseover="settimeout(\"document.location='http://www.google.com'\"),
2000">

I want to have a 2 seconds delay before it is directed to an URL when the
mouse is over the image.

However, it seems that setTimtOut does not like parameters in the function
part.


Inline JS is not the problem, it is your casing of the word
setTimeout. Capitalize the `T` in Timeout.
Jul 23 '05 #5
Lasse Reichstein Nielsen wrote:
"QA" <QA@alexa.com> writes:
<img src=http://xxx.com/yyy.jpg [...]>


There are quite a lot of errors in these lines.

First of all, the src attribute value must be quoted.


*This* "src" attribute value must be quoted
because it contains a "/" (slash) character.
PointedEars
--
Never trust anything you buy with good intentions
Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
2
by: Athanasius | last post by:
Could someone shed some light as to why the following setTimeout function will not work on the Mac IE5.2? It does however work on PC(Forefox,Netscape,IE) & Mac(Safari,Firefox). Here is the script,...
12
by: Andrew Poulos | last post by:
With the following code I can't understand why this.num keeps incrementing each time I create a new instance of Foo. For each instance I'm expecting this.num to alert as 1 but keeps incrementing. ...
28
by: Andre | last post by:
Hi, Does anyone know whether the ECMA, or an other standard document, specifies a maximum for the value that can be pass to the setTimeOut() function in Javascript? Andre
4
by: E | last post by:
I am having trouble with setTimeout working on a second call to the setTimeout function from a second page which is an html page. Here is the scenario. I have a web page and onload it calls a...
10
by: Shadow Lynx | last post by:
That subject packs a whallop, so let me explain in better detail what's happening and how it relates to ASPX pages... In a nutshell, if the first <script /on a page is of type "text/vbscript",...
15
by: nikki_herring | last post by:
I am using setTimeout( ) to continuously call a function that randomly rotates/displays 2 images on a page. The part I need help with is the second image should rotate 3 seconds after the first...
3
by: naurus | last post by:
i'd like to know what set timeout does after its finished. I have a script that starts a timeout right before sending an SJaX request that timesout after 1000 milliseconds and abort()s the SJaX...
10
by: Frank O'Hara | last post by:
Hello everyone, I'm just learning some of the depth that Javascript has to offer. I have to say that it is quite amazing. Anyway, I'm translating some of my older, classical code to try to take...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.