Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Calling Jscript inside a Modal Window

15 views
Skip to first unread message

Joey

unread,
Feb 8, 2004, 3:08:29 AM2/8/04
to
Hey,
I'v gotta modal window called using - window.ShowModalDialog("MyPage.aspx")
Inside this page I'v got an "a href" calling a java script inside the modal
dialog
But when click the a href, instead of running the script, the modallic
window opens a new window looking for my Java script function
Help needed asap!
Thanx ahead!

--Joey


Roland Hall

unread,
Feb 8, 2004, 6:40:12 AM2/8/04
to
"Joey" wrote:
: I'v gotta modal window called using -

Joey...

Showing some relevant code will get you an answer faster.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp


Martin Honnen

unread,
Feb 8, 2004, 6:13:42 AM2/8/04
to

Joey wrote:

> I'v gotta modal window called using - window.ShowModalDialog("MyPage.aspx")
> Inside this page I'v got an "a href" calling a java script inside the modal
> dialog
> But when click the a href, instead of running the script, the modallic
> window opens a new window looking for my Java script function

Don't use
<a href="javascript: code">
simply use
<a href="#"
onclick="code; return false;">

--

Martin Honnen
http://JavaScript.FAQTs.com/

Lasse Reichstein Nielsen

unread,
Feb 8, 2004, 7:37:26 AM2/8/04
to
Martin Honnen <Martin...@t-online.de> writes:

> simply use
> <a href="#"
> onclick="code; return false;">

Actually, I'd recommend against href="#" too.

If Javascript is not available, the link will be unusable. That is bad
design. You should use some href that makes sense, if nothing else
href="whyThisPageNeedsJS.html" . The "#" link will either do nothing,
jump to the top of the page, or reload the page, depending on the
browser. That is not what you want (except perhaps the "do nothing"
option). (Btw, the shortest legal URL is the empty one, so you could
also write href="", which is, if nothing else, shorter, and has less
chance of reloading the page).

If you can't find any href that makes sense, it is a good sign that you
are using the wrong HTML element. What you have is something that has
an effect when clicked, not something that links to another ressource.
That is the job of a button, not a link, so just use a button and you
won't have to invent a meaningfull URL for a href.

/L
--
Lasse Reichstein Nielsen - l...@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'

Joey

unread,
Feb 8, 2004, 7:53:14 AM2/8/04
to
First Thanx for the replys!
Though I need to say that the problem was not to give a javascript event to
an a href object
But to do so whilst in Modallic Window
About some relevant code:
"Javascript:aonClick();"
Thanx again!

-- Joey

"Roland Hall" <nobody@nowhere> wrote in message
news:ukBowMj7...@TK2MSFTNGP11.phx.gbl...

Roland Hall

unread,
Feb 9, 2004, 1:48:00 AM2/9/04
to
"Joey" wrote:
: First Thanx for the replys!

: Though I need to say that the problem was not to give a javascript event
to
: an a href object
: But to do so whilst in Modallic Window
: About some relevant code:
: "Javascript:aonClick();"
: Thanx again!

Joey...

aonClick() is not a valid command so it would have to be a function.
It is also not relevant code. I wanted you to show the link you're
referring to that you have inside the Modal window.
You're not opening a Modal window, you're inside a Modal window with an
'href' link calling a javascript script.
So, we need to see the link and possibly also the script.

Joey

unread,
Feb 9, 2004, 1:52:05 AM2/9/04
to
Okokokok, You missunderstood me
I'll give you the easyest example:
I'v got in a modallic window the next code:
<a href="javascript::alert();>Press Me!</a>
Try running this line in a normal window - you'll get an empty alert,
But if your run the same like of code in a modallic window - it will open an
empty web page!
Thanks again

-- Joey
"Roland Hall" <nobody@nowhere> wrote in message

news:#vekCOt7...@TK2MSFTNGP12.phx.gbl...

Martin Honnen

unread,
Feb 9, 2004, 9:20:42 AM2/9/04
to

Lasse Reichstein Nielsen wrote:

> Martin Honnen <Martin...@t-online.de> writes:
>
>
>>simply use
>> <a href="#"
>> onclick="code; return false;">
>
>
> Actually, I'd recommend against href="#" too.
>
> If Javascript is not available, the link will be unusable. That is bad
> design.

Well, the original poster was talking about a modal window and that can
only be open if JavaScript is available.

Saint Jude

unread,
Feb 9, 2004, 10:42:30 AM2/9/04
to
More confusion, Joey !

The syntax, "javascript::alert()" is either a) wrong or b) new to me.
...basically you would only use *one* colon.

To be honest, if it works in a normal window, I dunno why I doesn't in a
modal.
Maybe they're more fussy about syntax.
Try the correct version with a single colon first.
If that doesn't work.....

As a previous poster has said, executing functions isn't really the
proper use for links. Their use in this way, with the "javascript: ..."
protocol is a bit of a hangover from the "old days".

Really, you should write: onclick = "alert( )" .. and that's it.
If the function you are calling is actually declared on the main window,
then you'll need to get the function via that, with a reference to the main
window
(which needs to be passed as an argument when the modal is opened, I
believe)
So

onclick = "[ openerRef ].[ functionName ]( args )"

I can see why you might still want to use a link href though.
It can make rollovers easier with a little canny use of CSS.

Luck to you

Jude

Joey <n_n...@hotmail.com> wrote in message
news:uCOUEjt7...@tk2msftngp13.phx.gbl...

Roland Hall

unread,
Feb 10, 2004, 3:10:37 AM2/10/04
to
"Saint Jude" wrote:
: More confusion, Joey !

:
: The syntax, "javascript::alert()" is either a) wrong or b) new to me.
: ...basically you would only use *one* colon.
:
: To be honest, if it works in a normal window, I dunno why I doesn't in a
: modal.
: Maybe they're more fussy about syntax.
: Try the correct version with a single colon first.
: If that doesn't work.....
:
: As a previous poster has said, executing functions isn't really the
: proper use for links. Their use in this way, with the "javascript: ..."
: protocol is a bit of a hangover from the "old days".
:
: Really, you should write: onclick = "alert( )" .. and that's it.
: If the function you are calling is actually declared on the main window,
: then you'll need to get the function via that, with a reference to the
main
: window
: (which needs to be passed as an argument when the modal is opened, I
: believe)
: So
:
: onclick = "[ openerRef ].[ functionName ]( args )"
:
: I can see why you might still want to use a link href though.
: It can make rollovers easier with a little canny use of CSS.

Actually I agree with most Jude wrote here and I must say I missed the
double colon. I'm almost sure it is just a typo here since I doubt Joey
copy/pasted.

However, I am also having the same issue so I'm not sure if it is possible
with Modal/Modeless windows. This may be by design but I've read some
articles that say you need to pass everything to them through the arguments.

As one example of a normal popup window vs a modal/modeless window, the
filename is not required. You can reference it as:

var w = window.open('','windowname','width=200, height=100');

...and then reference that window with the variable w. Modal windows do not
appear to allow this and require you pass through the arguments parameter.

I'm working with showModalDialog and showModelessDialog. If you're working
with something else, then please let me know.

However, you can turn everything off in a normal popup window so does your
window have to be modal for what you want?
You know, you cannot even right-click a Modal window. You can but nothing
returns.

Roland Hall

unread,
Feb 10, 2004, 5:02:05 AM2/10/04
to
"Roland Hall" wrote:

To add, here is an interesting article, although dated, which might explain
some things. There are errors in this document because you can work with
Modals and frames and with Modals -> Modals passing arguments.

http://developer.netscape.com/viewsource/goodman_modal/goodman_modal.html

Joey

unread,
Feb 10, 2004, 9:03:05 AM2/10/04
to
Jude - srry for all the mess lolz
About the double colons - it's my typo mistake - I meant only one...
But although you all did help me, you miss understood my problem
The problem is calling a Java Script function in a Modallic Window - NOT
from JUST an href,
I'll give a clearer example:
<html>
<!-- This web page is called as a Modallic Window! -->
<input type=button onclick="myfunc();" />
<script language=jscript>
funcion myfunc()
{
alert();
}
</script>
</html>

Notice this code WILL work on a normal window,
BUT, running it on a modallic window will a cause a different window to be
opened!
Thanks again

-- Joey
"Roland Hall" <nobody@nowhere> wrote in message

news:ONd4jf77...@tk2msftngp13.phx.gbl...

Michael Harris \(MVP\)

unread,
Feb 10, 2004, 7:35:08 PM2/10/04
to
Joey wrote:
> Okokokok, You missunderstood me
> I'll give you the easyest example:
> I'v got in a modallic window the next code:
> <a href="javascript::alert();>Press Me!</a>


Script defined in an href attribute should return a url *or* return false to
cancel the default action of clicking on a link (i.e., navigate the current
window to the url specified in the href attribute).

<a href="javascript:myFunc();>Press Me!</a>

with...

function myFunc()
{
//do something useful...
return false;
}

A better choice is to use the onclick event and an empty href...

<a href="" onclick="javascript::myFunc();>Press Me!</a>

In any case, modal/modeless *dialog* windows will open links in a new window
*by design*.


> Try running this line in a normal window - you'll get an empty alert,
> But if your run the same like of code in a modallic window - it will
> open an empty web page!

--
Michael Harris
Microsoft.MVP.Scripting

Microsoft® Windows®2000 Scripting Guide
http://www.microsoft.com/technet/scriptcenter/scrguide/sagsas_overview.asp

TechNet Script Center Sample Scripts
http://www.microsoft.com/technet/scriptcenter/default.asp
Download in HTML Help format (searchable and indexed)
http://www.microsoft.com/downloads/release.asp?ReleaseID=38942

WSH 5.6 documentation download
http://www.microsoft.com/downloads/details.aspx?FamilyId=01592C48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en

Lasse Reichstein Nielsen

unread,
Feb 11, 2004, 3:43:32 PM2/11/04
to
"Michael Harris \(MVP\)" <mikhar at mvps dot org> writes:

> Joey wrote:

>> <a href="javascript::alert();>Press Me!</a>

> Script defined in an href attribute should return a url *or* return false to
> cancel the default action of clicking on a link (i.e., navigate the current
> window to the url specified in the href attribute).

I think you are confuzing some things here.

It should not return an URL. Whatever it returs is used as HTML code to
*replace* the current page. Returning an URL would give you a blank page
with the URL as text. Returning false would give you a blank page with
"false" written on it.

Generally, you should not use javascript: hrefs at all, but instead
use the onclick attribute:
<a href="thisPageRequiresJS.html" onclick="myFunc();return false;">
This is the correct place to return false from to cancel the normal
behavior of the link. Remember to have a meaningfull URL for people
with Javascript turned off or otherwise unavailable.

> A better choice is to use the onclick event and an empty href...

Indeed, except I don't recommend the empty href.

> <a href="" onclick="javascript::myFunc();>Press Me!</a>

The "::" is one colon too many, but the entire "javascript:" can
be removed. In other browsers than IE, it is merely read as a
label named "javascript". In IE, it does select the language of
the event handler, but Javascript/JScript is the default.

Roland Hall

unread,
Feb 11, 2004, 6:38:35 PM2/11/04
to
"Joey" wrote:
: Jude - srry for all the mess lolz

: About the double colons - it's my typo mistake - I meant only one...
: But although you all did help me, you miss understood my problem
: The problem is calling a Java Script function in a Modallic Window - NOT
: from JUST an href,
: I'll give a clearer example:
: <html>
: <!-- This web page is called as a Modallic Window! -->
: <input type=button onclick="myfunc();" />
: <script language=jscript>
: funcion myfunc()
: {
: alert();
: }
: </script>
: </html>
:
: Notice this code WILL work on a normal window,
: BUT, running it on a modallic window will a cause a different window to be
: opened!

Well, it appears Michael Harris answered the question of whether or not it
is by design to open a new window. I don't use the <a href> anyway and I
have test it with that and with a <span onclick...> and it's the same
issue.

I believe the Modal and Modeless Windows are designed to be menu holders or
custom information dialogs and not so much a usable window, like a popup.
What's confusing is it's called a Modal Window meaning, at least to me, it
should be just like a popup window but maintain focus. However, I find that
I am wrong in this assumption because I've written many popup window
routines and none of them work correctly with the Modal or Modeless as you
have requested.

Joey

unread,
Feb 12, 2004, 10:48:30 AM2/12/04
to
Hey Roland,
I have found a work around for this problem - an ugly one, but a woring one
;)
inside the modallic window, put ONLY an IFRAM, that contains the actual page
you want to show in the modallic state.
This WILL solve the problem...
BUT - a new problem is show - if you notice, no matter what you write in the
modallic window's title,
It will automatically add:
"--WebPage"
Is there a way to delete this "addin" for the title?
Thanks again!

-- Joey
"Roland Hall" <nobody@nowhere> wrote in message

news:#By9eMP8...@TK2MSFTNGP11.phx.gbl...

Michael Harris \(MVP\)

unread,
Feb 12, 2004, 7:16:00 PM2/12/04
to
> in the modallic window's title,
> It will automatically add:
> "--WebPage"
> Is there a way to delete this "addin" for the title?


No, it's there deliberately so that a malicious site can't display a page
the mimics a trusted Windows system dialog.

0 new messages