Connecting Tech Pros Worldwide Forums | Help | Site Map

prompt being blocked by popup blockers

Newbie
 
Join Date: Sep 2006
Posts: 2
#1: Jan 4 '07
I am having a problem with the prompt message being blocked by popup blockers. (I think)

I have the following javascript code on my page and some customers are having a problem with the prompt message. They get the confirm message and answer yes and then it immedietly puts up the message "Approval Process cancelled". Other customers are fine.

I figure this is due to popup blockers on thier box. This is what I have tried and nothing seems to fix it on this box.

1. Enable popups on the page.
2. Clear temp files and cookies
3. Hold Ctrl key when doing the approval
4. Allow the web site under the pop-up blocker in the internet tools. (In the privacy setting tab)

Nothing seems to work. They can go to another machine and it allows them to approve but I need to find out what is stopping it on this machine.


The asp page calls a javascript function that contains the following codewhen a button is clicked.


Expand|Select|Wrap|Line Numbers
  1. if (confirm("Are you sure you wish to APPROVE this property?") == false)
  2. {
  3.     return;
  4. }        
  5.  
  6. var answer = prompt("Please enter your First Name, Last Name and Title.","");
  7.  
  8. if (answer == null) 
  9. {
  10.  // cancel
  11.  alert("Approval Process cancelled");
  12.  return;
  13. }
  14.  
I would appreciate any help

acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#2: Jun 3 '08

re: prompt being blocked by popup blockers


The problem is IE7 has disabled prompt by default. Either change the settings on each browser or use an alternative - here's one.
Needs Regular Fix
 
Join Date: Jun 2006
Posts: 424
#3: Jun 3 '08

re: prompt being blocked by popup blockers


There are easier ways, including a hidden input field on your page.

Nothing completely mimics a window.prompt, but you can come close with
something like this- customise the style to suit.
Expand|Select|Wrap|Line Numbers
  1. // Start with an object to hold a couple methods
  2.  
  3. if(typeof Run!= 'object')Run={};
  4.  
  5. // event handler method
  6. Run.addEve= function(who,what,fun){
  7.     if(who.addEventListener) who.addEventListener(what,fun,false);
  8.     else if(who.attachEvent) who.attachEvent('on'+what,fun);
  9. }
  10.  
  11. // faux prompt:
  12. Run.prompter= function(str1,str2,callback){
  13. // first insert a layer to overlay the page- 
  14. // the prompt isn't truly modal, but mouse events are blocked
  15. // until you deal with the prompt.
  16.  
  17.     var isIE= !document.addEventListener && document.attachEvent;
  18.     var sy= document.documentElement.scrollTop || 
  19.     document.body.scrollTop;
  20.     var py= screen.height+sy;
  21.  
  22.     var P1= document.createElement('div');
  23.     var sty= {position:'absolute',top:'0px',left:'0px',
  24.     width:'100%',height:py+'px',
  25.     zIndex:'1000000000',backgroundColor:'white'};
  26.  
  27.     if(isIE) sty.filter= 'alpha(opacity=10)' ;
  28.     else sty.opacity= '.2';
  29.  
  30.     for(var p in sty) P1.style[p]= sty[p];
  31.     P1.id= 'modalDiv';
  32.     document.body.appendChild(P1);
  33.  
  34.     // create the prompt div
  35.     var elDiv= document.createElement('div');
  36.     elDiv.id= 'promptDiv';
  37.     sty= {position:'absolute', top:(100+sy)+'px',left:'25%',width:'30em',
  38.     border:'2px ridge black',backgroundColor:'#ddd',color:'black',
  39.     zIndex:'1000000001',paddingBottom:'1em'};
  40.  
  41.     for(var p in sty) elDiv.style[p]= sty[p];
  42.     var el= document.createElement('h3');
  43.     el.appendChild(document.createTextNode(str1));
  44.     elDiv.appendChild(el);
  45.  
  46.     // input and buttons
  47.     el= document.createElement('p');
  48.     elDiv.appendChild(el);
  49.     var elT= document.createElement('input');
  50.     elT.type= 'text';
  51.     elT.size= '24';
  52.     elT.value= str2 || '';
  53.     el.appendChild(elT);
  54.     var elB= document.createElement('button');
  55.     elB.appendChild(document.createTextNode('OK'));
  56.     el.appendChild(elB);
  57.     var elB2= elB.cloneNode(false);
  58.     elB2.appendChild(document.createTextNode('Cancel'));
  59.     el.appendChild(elB2);
  60.  
  61.     // remove it (after callback)
  62.     var zap= function(){
  63.         setTimeout(function(){
  64.             document.body.removeChild(
  65.             document.getElementById('promptDiv'));
  66.             document.body.removeChild(
  67.             document.getElementById('modalDiv'));
  68.         },
  69.         250);
  70.     }
  71.     // assign handlers- enter key will work as well as mouse click
  72.     if(typeof callback== 'function'){
  73.         Run.addEve(elB,'click',function(){ callback(elT.value) });
  74.     }
  75.     Run.addEve(elB,'click',zap);
  76.     Run.addEve(elB2,'click',zap);
  77.     document.body.appendChild(elDiv);
  78.     elT.focus();
  79. }
// test case- arguments: prompt text, default input, callback function

Run.prompter('Type a value','',function(tem){alert(tem)});
Reply