LuckyCold
asked on
JavaScrip popup box with OK option only
Hi JavaScript experts,
I have a html page which has a hyperlink to open the pps (powerpoint file). It takes quite some times to load the pps, I want to pop up a warning messagebox with "OK" when user clicks hyperlink. then when user click "ok" it will kick off hyperlink to load the pps.
Please advise. Thanks
I have a html page which has a hyperlink to open the pps (powerpoint file). It takes quite some times to load the pps, I want to pop up a warning messagebox with "OK" when user clicks hyperlink. then when user click "ok" it will kick off hyperlink to load the pps.
Please advise. Thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The solutions above will not work if the user does not have javascript.
The following will show the confirm download option if javascript is supported if the user does not have javascript they can still download the file.
Not everyone has Javascript or has it turned on, so it is important to give the option.
<html>
<head>
<script type="text/javascript">
<!--
function confirmPP(url) {
if (confirm("This file is quite large and will take time to download. Do you want to continue?")) {
window.location.href = url;
}
}
//-->
</script>
</head>
<body>
<a href="http://google.com" onclick="javascript:confir mPP(this.h ref);retur n false;">Open Powerpoint File</a>
</body>
</html>
The following will show the confirm download option if javascript is supported if the user does not have javascript they can still download the file.
Not everyone has Javascript or has it turned on, so it is important to give the option.
<html>
<head>
<script type="text/javascript">
<!--
function confirmPP(url) {
if (confirm("This file is quite large and will take time to download. Do you want to continue?")) {
window.location.href = url;
}
}
//-->
</script>
</head>
<body>
<a href="http://google.com" onclick="javascript:confir
</body>
</html>
The problem with using an alert is the user is forced to download the file even if they don't want to the confirm gives the user an option.
So the use of a confirm is most appropriate here.
But should you want to use the alert the code is below use the second link:
<html>
<head>
<script type="text/javascript">
<!--
function confirmPP(url) {
if (confirm("This file is quite large and will take time to download. Do you want to continue?")) {
window.location.href = url;
}
}
function alertPP(url) {
alert("This file is quite large and will take time to download. Do you want to continue?");
window.location.href = url;
}
//-->
</script>
</head>
<body>
<a href="http://google.com" onclick="javascript:confir mPP(this.h ref);retur n false;">Confirm Open Powerpoint File</a><br/>
<a href="http://google.com" onclick="javascript:alertP P(this.hre f);return false;">Alert Open Powerpoint File</a>
</body>
</html>
So the use of a confirm is most appropriate here.
But should you want to use the alert the code is below use the second link:
<html>
<head>
<script type="text/javascript">
<!--
function confirmPP(url) {
if (confirm("This file is quite large and will take time to download. Do you want to continue?")) {
window.location.href = url;
}
}
function alertPP(url) {
alert("This file is quite large and will take time to download. Do you want to continue?");
window.location.href = url;
}
//-->
</script>
</head>
<body>
<a href="http://google.com" onclick="javascript:confir
<a href="http://google.com" onclick="javascript:alertP
</body>
</html>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks everyone for the quick response.
I am testing it with all your suggestions. I let you how it goes tomorrow.
Thanks again.
I am testing it with all your suggestions. I let you how it goes tomorrow.
Thanks again.
ASKER
All your answers are working. I 'll split the points.
Thanks phatzer, russell2566 and ncoo.
Thanks phatzer, russell2566 and ncoo.
function loadSlowUrl(url) {
alert("The Link You Have Clicked On My Load Slow");
window.location.href = url;
}
</script>
<a href="JavaScript: loadSlowUrl('http://www.google.com');">Go Someplace</a>