Know page that fired an event

G

Guest

How do i identify the page that fired a method?

e.g.
page1.html
-----------
<Head>
<script>
document.write(myfun());
</script>

Assume that page1.html is in a frame (or iframe) in page.aspx. page.aspx
contains an include file say, myinc.js. myfun() is inside myinc.js. How do i
come to know that myfun() was fired from page1.html?
 
J

Jignesh Desai

Access frame from parent script

frame2.document.write("a message"); //any object can be called from frame2,
not just document.write

Access one frame from another
parent.frame2.document.write("Hi frame2");

Hope this helps.
Regards,
Jignesh Desai
www.dotnetjini.com
 
G

Guest

Let me put it the other way round.
I am invoking myfun() from page1.html. I need to get the id of page1.html
(without using 'this').

Jignesh Desai said:
Access frame from parent script

frame2.document.write("a message"); //any object can be called from frame2,
not just document.write

Access one frame from another
parent.frame2.document.write("Hi frame2");

Hope this helps.
Regards,
Jignesh Desai
www.dotnetjini.com
 
W

William F. Robertson, Jr.

If myfunc is triggered from an event, say a button click, you could look at
the event.srcElement control. If the button click caused myFunc to fire,
the button will be the srcElement. You then could determine the form, or
the containing control by stepping up the parent attribute of the control.

HTH,

bill

sunil philip said:
Let me put it the other way round.
I am invoking myfun() from page1.html. I need to get the id of page1.html
(without using 'this').
 
G

Guest

Thats my main problem. I am not firing the function from any event.I am
firing it from document.write.Any workaround for this??
 
W

William F. Robertson, Jr.

If your function is sitting in some global repository and is included into
page1.html, you can determine the scope the function is executing in with
the document.location.href for the full url to the page, or
document.location.pathname to get "/page1.html".

I tried using your document.write method but could not get the function to
fire properly, so I gave up on it, but the document.location will return the
scope the function is currently executing on.

bill
 
G

Guest

Ya, my function is sitting in global repository. The structure is something
like this

page1.aspx
------------
<script language="javascript" src="myGlobalFile.js"></script>


<frameset >
<frame name="header" src='Header.aspx' >
<frameset >
<frame id="contents">
<frame name="main" src='myPage.aspx' id="main">
</frameset>
</frameset>

myPage.aspx
---------------

<script>
document.write(top.funInmyGlobalFile());
</script>

<Iframe>
<frameset src = "page1.html">
</Iframe>

Now, page1.html contains the same
<script>
document.write(top.funInmyGlobalFile());
</script>

document.location.href will not give me Page1.html. It will only give me
page1.aspx when iam calling funInmyGlobalFile() from page1.html.
I want to identify thet funInmyGlobalFile() is fired from page1.html.
I hope u got a clear picture about my problem.
Sorry for keeping u in air.

Thanks
 
W

William F. Robertson, Jr.

I have tried and looked long and hard to find this solution. It appears the
only way to accomplish this is to add "this" as a parameter to your
funinmyGlobalFile function.

With the this parameter, you can pull the proper location.href to get the
html page of the caller.

I know this isn't quite the solution you were looking for, but this (pun) is
the best I could come up with.

bill
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top