Link to home
Start Free TrialLog in
Avatar of LuckyCold
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
SOLUTION
Avatar of Phatzer
Phatzer
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
<script>
      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>
Avatar of ncoo
ncoo

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:confirmPP(this.href);return false;">Open Powerpoint File</a>

</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:confirmPP(this.href);return false;">Confirm Open Powerpoint File</a><br/>
<a href="http://google.com" onclick="javascript:alertPP(this.href);return false;">Alert Open Powerpoint File</a>

</body>

</html>
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of LuckyCold

ASKER

Thanks everyone for the quick response.
I am testing it with all your suggestions. I let you how it goes tomorrow.

Thanks again.
All your answers are working. I 'll split the points.
Thanks phatzer, russell2566 and ncoo.