• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to call javascript function in the previous html file

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am learning Javascript and wrote the following code, but it does not display "show 2". It looks like the show2() function can not be found. Would you please let me know how to make it work? Thanks a lot.


<HTML>
<HEAD>
<TITLE></TITLE>
<script>
function show() {
document.write("show 1" ;
document.write('<INPUT TYPE="BUTTON" VALUE="Show me" onclick="show2()">');
}
function show2() {
document.write("show 2" ;

}
</script>
</HEAD>
<BODY>
<INPUT TYPE="BUTTON" VALUE="Show me" onclick="show()">;
</BODY>

</HTML>
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(next time you post code, disable smiles with the checkbox!)

When you use document.write after the page loads, it rewrites e entire page removing anything that was there before.

You need to use innerHTML or visibility to produce this effect.

Eric
 
kirts li
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for your reply! This is my first time to post message here.

I want to use the way like parent.whatmethod().show2() to refer to the first window, but I do not know how to write. Do you know can I do this way?

thanks!
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you write over the code it does not exsist any more, you can not reference it.
 
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since you mentioned it, and this is more of an academic question, at least in IE 5.5+ certain properties does not get "cleaned up" between the pages.
This could be used:
1. To catch the fact that user did "Open link in new window" versus just clicking on a link.

2. A function could be constructed as a string on one page. Than another page uses "eval" and than a function call.

Here is an example of second case:
Page1.html


Page2.html


I would, though, advise against used such tricks, since it more of using a bug, that likly will be fixed in a future.
 
It was the best of times. It was the worst of times. It was a tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic