Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > function call location?

Reply
Thread Tools

function call location?

 
 
Dr J R Stockton
Guest
Posts: n/a
 
      10-20-2011
Within a function body, and without using any of the arguments provided
in the call of the function, can the function obtain a reference to the
script element from within which it was called, and if so how? The
script element containing the definition of the function is of no
interest.

--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike 6.05 WinXP.
Web <http://www.merlyn.demon.co.uk/> - FAQ-type topics, acronyms, and links.
Command-prompt MiniTrue is useful for viewing/searching/altering files. Free,
DOS/Win/UNIX now 2.0.6; see <URL:http://www.merlyn.demon.co.uk/pc-links.htm>.
 
Reply With Quote
 
 
 
 
Antony Scriven
Guest
Posts: n/a
 
      10-21-2011
On Oct 20, 7:53 pm, Dr J R Stockton wrote:

> Within a function body, and without using any of the
> arguments provided in the call of the function, can the
> function obtain a reference to the script element from
> within which it was called, and if so how? The script
> element containing the definition of the function is of
> no interest.


In Firefox, for example, you might be able to do something
with e.stack:

<html>
<body>
<script id="foo">
var f = function(){
try{
qwoazlskjfalksdtjo4tjwf();
}catch(e){
alert(e.stack);
alert(window.documentElement.innerHTML);
}
};
</script
<script id="bar">
f();
</script>
</body>
</html>

What's your goal? --Antony
 
Reply With Quote
 
 
 
 
Dr J R Stockton
Guest
Posts: n/a
 
      10-22-2011
In comp.lang.javascript message <20ecde0b-c4e3-44df-9e34-a447753b0fb9@g1
6g2000yqa.googlegroups.com>, Thu, 20 Oct 2011 17:13:28, Antony Scriven
<(E-Mail Removed)> posted:

>On Oct 20, 7:53 pm, Dr J R Stockton wrote:
>
> > Within a function body, and without using any of the
> > arguments provided in the call of the function, can the
> > function obtain a reference to the script element from
> > within which it was called, and if so how? The script
> > element containing the definition of the function is of
> > no interest.

>
>In Firefox, for example, you might be able to do something
>with e.stack:
>
> <html>
> <body>
> <script id="foo">
> var f = function(){
> try{
> qwoazlskjfalksdtjo4tjwf();
> }catch(e){
> alert(e.stack);
> alert(window.documentElement.innerHTML);
> }
> };
> </script
> <script id="bar">
> f();
> </script>
> </body>
> </html>


As posted, that shows f(); in the window in FF 7.0.1 Win XP sp3.
After the obvious repair, it gives the first alert, then the error
message
Error: window.documentElement is undefined
Source File: file:///C:/HOMEPAGE/$1.htm Line: 10


>What's your goal? --Antony


The alert routine always used to pop up s simple dialogue, which could
be dragged around. Except for Opera, it was alas in the small font used
by Windows for the main menu bar. The page issuing the alert was
unchanged, apart from having lost focus.

A few updates ago, Opera changed to giving a non-standard but still
draggable alert dialogue, and greying the page into near unreadability -
which is bad if the alert is reporting details of an input error as is
commonly the case. It retained the more readable font. My easy fix was
to not use Opera for such pages.

Since my most recent Firefox upgrade, from 3.6.23 to 7.0.1, FF's alert
is like opera's, except that it is not draggable (so may cover what one
wants to read) and uses the hard-to-read font.

My Web site has, counting with MiniTrue, 566 calls of alert.

So I was thinking of replacing window.alert with another function Alert
or by editing replace calls of alert with ones of Alert by editing the
source (with MiniTrue). The new function Alert would insert a suitable
box somewhere on the page. In practice, inserting before or after the
script element could be a good default (a second argument, if provided,
would choose a location). Alternatively, the function Alert could open
a new window.

The same would apply to window.confirm and window.prompt.

<FAQENTRY> replacement for alert confirm prompt </FAQENTRY>

--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike 6.05 WinXP.
Web <http://www.merlyn.demon.co.uk/> - FAQ-type topics, acronyms, and links.
Command-prompt MiniTrue is useful for viewing/searching/altering files. Free,
DOS/Win/UNIX now 2.0.6; see <URL:http://www.merlyn.demon.co.uk/pc-links.htm>.
 
Reply With Quote
 
Scott Sauyet
Guest
Posts: n/a
 
      10-23-2011
Dr J R Stockton wrote:
> [ ... alert boxes problematic ... ]
> My Web site has, counting with MiniTrue, 566 calls of alert.
>
> So I was thinking of replacing window.alert with another function Alert
> or by editing replace calls of alert with ones of Alert by editing the
> source (with MiniTrue). *The new function Alert would insert a suitable
> box somewhere on the page. *In practice, inserting before or after the
> script element could be a good default (a second argument, if provided,
> would choose a location). *Alternatively, the function Alert could open
> a new window.
>
> The same would apply to window.confirm and window.prompt.


Why would it matter where in the markup the box was placed?
Presumably you would want this to sit in a higher z-index than the
surrounding content, so wouldn't simply placing this with
position:absolute (and allowing whatever drag options you choose) be a
sensible alternative. Then the box could be placed in an arbitrary
spot in the markup. (For such things, I usually simply append to the
end of the BODY.)

There are numerous libraries available to add dialogs to web pages.
Can you simply use one of them?

As the the original question, I rather doubt there would be any clean
way to do this, but by throwing and catching an exception, you might
be able to track the calling function to its URL and line number in
some browsers.

-- Scott
 
Reply With Quote
 
Antony Scriven
Guest
Posts: n/a
 
      10-24-2011
On Oct 22, 6:43 pm, Dr J R Stockton wrote:

> > In comp.lang.javascript message
> > <20ecde0b-c4e3-44df-9e34-a447753b0fb9@g1
> > 6g2000yqa.googlegroups.com>, Thu, 20 Oct 2011 17:13:28,
> > Antony Scriven <(E-Mail Removed)> posted:
> >
> > >On Oct 20, 7:53 pm, Dr J R Stockton wrote:

> >
> > > > Within a function body, and without using any of the
> > > > arguments provided in the call of the function, can the
> > > > function obtain a reference to the script element from
> > > > within which it was called, and if so how? The script
> > > > element containing the definition of the function is of
> > > > no interest.

> >
> > >In Firefox, for example, you might be able to do something
> > >with e.stack:

> >
> > > <html>
> > > <body>
> > > <script id="foo">
> > > var f = function(){
> > > try{
> > > qwoazlskjfalksdtjo4tjwf();
> > > }catch(e){
> > > alert(e.stack);
> > > alert(window.documentElement.innerHTML);
> > > }
> > > };
> > > </script
> > > <script id="bar">
> > > f();
> > > </script>
> > > </body>
> > > </html>

> >
> > As posted, that shows f(); in the window in FF 7.0.1 Win

XP sp3.
> > After the obvious repair, it gives the first alert, then the

error
> > message
> > Error: window.documentElement is undefined
> > Source File: file:///C:/HOMEPAGE/$1.htm

Line: 10

Sorry, I seem to have had a bit of an editing nightmare with
that article. That should be document.documentElement.

> > >What's your goal? --Antony

> >
> > [...]
> >
> > So I was thinking of replacing window.alert with
> > another function Alert or by editing replace calls of
> > alert with ones of Alert by editing the source (with
> > MiniTrue). The new function Alert would insert
> > a suitable box somewhere on the page. In practice,
> > inserting before or after the script element could be
> > a good default (a second argument, if provided, would
> > choose a location). Alternatively, the function Alert
> > could open a new window.
> >
> > [...]


As Scott already said, why does it need to go near the
script element? --Antony
 
Reply With Quote
 
Dr J R Stockton
Guest
Posts: n/a
 
      10-24-2011
In comp.lang.javascript message <d29d6f09-972a-4e45-85a9-85d2c052da38@hj
4g2000vbb.googlegroups.com>, Sun, 23 Oct 2011 10:00:18, Scott Sauyet
<(E-Mail Removed)> posted:

>Dr J R Stockton wrote:
>> [ ... alert boxes problematic ... ]
>> My Web site has, counting with MiniTrue, 566 calls of alert.
>>
>> So I was thinking of replacing window.alert with another function Alert
>> or by editing replace calls of alert with ones of Alert by editing the
>> source (with MiniTrue). *The new function Alert would insert a suitable
>> box somewhere on the page. *In practice, inserting before or after the
>> script element could be a good default (a second argument, if provided,
>> would choose a location). *Alternatively, the function Alert could open
>> a new window.
>>
>> The same would apply to window.confirm and window.prompt.



>Why would it matter where in the markup the box was placed?


For my pages, that would in general put it near, but not on, the cause
of the Alert, which would be a good start.


>Presumably you would want this to sit in a higher z-index than the
>surrounding content, so wouldn't simply placing this with
>position:absolute (and allowing whatever drag options you choose) be a
>sensible alternative.


It would. Remember that the most effective way of finding a good
solution is to present a possible solution in a Usenet newsgroup. I'd
never given any thought to z-index until last week, when I wanted
(because of another nasty in Firefox 7) to put a large outline - the
border of an empty div - on a page, position absolute. That's OK, and
it was transparent; but it masked clicks on what was showing through,
and z-index fixed that. However, ISTM that now I'd have to discover the
Y-position to give it.

> Then the box could be placed in an arbitrary
>spot in the markup. (For such things, I usually simply append to the
>end of the BODY.)
>
>There are numerous libraries available to add dialogs to web pages.
>Can you simply use one of them?


It will take me longer to find and understand a sound one than to
implement an acceptable solution using a well-placed and initially non-
displayed div element, accessed by getElementById.

>As the the original question, I rather doubt there would be any clean
>way to do this, but by throwing and catching an exception, you might
>be able to track the calling function to its URL and line number in
>some browsers.


Must be all likely GUI browsers, at least.

--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
<http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
<http://www.merlyn.demon.co.uk/clpb-faq.txt> RAH Prins : c.l.p.b mFAQ;
<ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip> Timo Salmi's Turbo Pascal FAQ.
 
Reply With Quote
 
Scott Sauyet
Guest
Posts: n/a
 
      10-25-2011
Dr J R Stockton wrote:
> Scott Sauyet posted:
>> Presumably you would want this to sit in a higher z-index than the
>> surrounding content, so wouldn't simply placing this with
>> position:absolute (and allowing whatever drag options you choose) be a
>> sensible alternative.

>
> It would. *Remember that the most effective way of finding a good
> solution is to present a possible solution in a Usenet newsgroup.
> [ ... ]





>> There are numerous libraries available to add dialogs to web pages.
>> Can you simply use one of them?

>
> It will take me longer to find and understand a sound one than to
> implement an acceptable solution using a well-placed and initially non-
> displayed div element, accessed by getElementById.


Ok, but welcome to the world of web-scripting. What once seem to be
acceptable solutions often turn out to be less than acceptable as
reports from the wild world of the web pour in.


>> As the the original question, I rather doubt there would be any clean
>> way to do this, but by throwing and catching an exception, you might
>> be able to track the calling function to its URL and line number in
>> some browsers.

>
> Must be all likely GUI browsers, at least.


As I said, I doubt there's a real solution to this.

Good luck,

-- Scott
 
Reply With Quote
 
Dr J R Stockton
Guest
Posts: n/a
 
      10-25-2011
In comp.lang.javascript message <8fa806c9-a274-4ca7-b6be-8d6235d2f7ae@s1
4g2000vbj.googlegroups.com>, Mon, 24 Oct 2011 02:11:46, Antony Scriven
<(E-Mail Removed)> posted:

>As Scott already said, why does it need to go near the
>script element? --Antony


Because that, as a default, will in my pages usually be near enough
where I would choose to have it appear. Then, only where that is not
near enough will I need to indicate a specific location.

--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms and links;
Astro stuff via astron-1.htm, gravity0.htm ; quotings.htm, pascal.htm, etc.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
 
Reply With Quote
 
Scott Sauyet
Guest
Posts: n/a
 
      10-26-2011
Dr J R Stockton wrote:
> Antony Scriven posted:
>
>> As Scott already said, why does it need to go near the
>> script element?

>
> Because that, as a default, will in my pages usually be near enough
> where I would choose to have it appear. *Then, only where that is not
> near enough will I need to indicate a specific location.


I had been trying to point out, though, that mark-up proximity need
have no bearing on visible proximity.

What would you expect if the alert was called from a script running in
the HEAD?

-- Scott
 
Reply With Quote
 
Dr J R Stockton
Guest
Posts: n/a
 
      10-26-2011
In comp.lang.javascript message <0d36dd0b-5638-44d2-9102-f88fffbe44fc@f3
6g2000vbm.googlegroups.com>, Tue, 25 Oct 2011 05:13:05, Scott Sauyet
<(E-Mail Removed)> posted:
>Dr J R Stockton wrote:


>> It will take me longer to find and understand a sound one than to
>> implement an acceptable solution using a well-placed and initially non-
>> displayed div element, accessed by getElementById.

>
>Ok, but welcome to the world of web-scripting. What once seem to be
>acceptable solutions often turn out to be less than acceptable as
>reports from the wild world of the web pour in.


It's always nice to hear from an actual reader with a good suggestion
that can easily be implemented.


The best thing would be for browser writers to see sense, and make the
alert function do the same, and correct, thing in all browsers.

In IE 8, Firefox 3, Safari 5.1.1, Chrome 14 & 15, function alert does
the right thing - a draggable box that holds focus with respect to the
issuing page.

In Firefox 7 and Opera 11.52, the page is greyed, which is very bad;
in FF7, the alert cannot even be dragged.

In Opera 11.52, one can copy from the text shown, which is good; and the
text is larger, also good.

I don't think any of them allow the text to be zoomed, as obviously they
ought. I don't think any allow font selection (an alert may want fixed
pitch). I don't think any are good at identifying, in words, the
browser and the page.

Fancy alerts are acceptable, if they are a new and not a substitute
feature and have a new name.


FYI - Chrome is now 15.0.

--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05.
Website <http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc. : <http://www.merlyn.demon.co.uk/programs/> - see in 00index.htm
Dates - miscdate.htm estrdate.htm js-dates.htm pas-time.htm critdate.htm etc.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to call function whose function call with arguments is in astring Options grbgooglefan C Programming 4 01-30-2008 05:12 PM
How to call function whose function call with arguments is in astring grbgooglefan C++ 2 01-30-2008 07:18 AM
How to call function whose function call with arguments is in astring Options grbgooglefan C Programming 0 01-30-2008 04:19 AM
defined? for recursive function call v/s defined? for function call stack Alok Ruby 3 04-13-2006 11:53 AM
write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter komal C++ 6 01-25-2005 11:13 AM



Advertisments