function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
trick.ax1374trick.ax1374 

javascript and VF

 

Hi friends,

 

Below given code I have taken directly from a tutoria.It works in the tutorial.However,when I run in salesforce,It just doesn't do anything .I do not what is wrong.Can somebody point out.

<Apex:page >
<html>
<head>
<script type="text/javascript">
function OnUnload()
{
alert ("The current document will be unloaded!");
}
</script>
</head>
<body onunload="OnUnload()">

<p>Close this window or press F5 to reload the page.</p>

</body>
</html>
</apex:page>

 

 

Thanks,

Trick

stcforcestcforce

not an expert or remotely close, but

a) i'm reasonably sure that apex page tags will add html head and body components and i'm not sure how well these will play with your html.

b) if wanting to add the event to the SF-generated body, mihgt have to use addEvent of javascript (i think)

b) Use your development tools built into your browser to see how apex has processed your page. Can test ability to reach objects, methods via the console.

bob_buzzardbob_buzzard

stcforce is correct.  

 

If you want to define this on the body, you have to remove the header, sidebar and probably standard stylesheets.

 

If not, you can add it via javascript. Visualforce adds its own onunload handler, so you'd really want to add yours to the beginning of the chain so that you don't break theirs.  I wrote a blog post on creating an onload handler in a vf page that should be straightforward to adapt, though you'd need to make yours fire first I think:

 

http://bobbuzzard.blogspot.co.uk/2011/05/onload-handling.html

 

Also, be aware that some browsers block alerts in onunload handlers - google chrome for one.