prompt being blocked by popup blockers

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jtaylor
    New Member
    • Sep 2006
    • 3

    prompt being blocked by popup blockers

    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.


    [CODE=javascript]if (confirm("Are you sure you wish to APPROVE this property?") == false)
    {
    return;
    }

    var answer = prompt("Please enter your First Name, Last Name and Title.","");

    if (answer == null)
    {
    // cancel
    alert("Approval Process cancelled");
    return;
    }
    [/CODE]
    I would appreciate any help
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    The problem is IE7 has disabled prompt by default. Either change the settings on each browser or use an alternative - here's one.

    Comment

    • mrhoo
      Contributor
      • Jun 2006
      • 428

      #3
      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.
      Code:
      // Start with an object to hold a couple methods
      
      if(typeof Run!= 'object')Run={};
      
      // event handler method
      Run.addEve= function(who,what,fun){
      	if(who.addEventListener) who.addEventListener(what,fun,false);
      	else if(who.attachEvent) who.attachEvent('on'+what,fun);
      }
      
      // faux prompt:
      Run.prompter= function(str1,str2,callback){
      // first insert a layer to overlay the page- 
      // the prompt isn't truly modal, but mouse events are blocked
      // until you deal with the prompt.
      
      	var isIE= !document.addEventListener && document.attachEvent;
      	var sy= document.documentElement.scrollTop || 
      	document.body.scrollTop;
      	var py= screen.height+sy;
      
      	var P1= document.createElement('div');
      	var sty= {position:'absolute',top:'0px',left:'0px',
      	width:'100%',height:py+'px',
      	zIndex:'1000000000',backgroundColor:'white'};
      
      	if(isIE) sty.filter= 'alpha(opacity=10)' ;
      	else sty.opacity= '.2';
      
      	for(var p in sty) P1.style[p]= sty[p];
      	P1.id= 'modalDiv';
      	document.body.appendChild(P1);
      
      	// create the prompt div
      	var elDiv= document.createElement('div');
      	elDiv.id= 'promptDiv';
      	sty= {position:'absolute', top:(100+sy)+'px',left:'25%',width:'30em',
      	border:'2px ridge black',backgroundColor:'#ddd',color:'black',
      	zIndex:'1000000001',paddingBottom:'1em'};
      
      	for(var p in sty) elDiv.style[p]= sty[p];
      	var el= document.createElement('h3');
      	el.appendChild(document.createTextNode(str1));
      	elDiv.appendChild(el);
      
      	// input and buttons
      	el= document.createElement('p');
      	elDiv.appendChild(el);
      	var elT= document.createElement('input');
      	elT.type= 'text';
      	elT.size= '24';
      	elT.value= str2 || '';
      	el.appendChild(elT);
      	var elB= document.createElement('button');
      	elB.appendChild(document.createTextNode('OK'));
      	el.appendChild(elB);
      	var elB2= elB.cloneNode(false);
      	elB2.appendChild(document.createTextNode('Cancel'));
      	el.appendChild(elB2);
      
      	// remove it (after callback)
      	var zap= function(){
      		setTimeout(function(){
      			document.body.removeChild(
      			document.getElementById('promptDiv'));
      			document.body.removeChild(
      			document.getElementById('modalDiv'));
      		},
      		250);
      	}
      	// assign handlers- enter key will work as well as mouse click
      	if(typeof callback== 'function'){
      		Run.addEve(elB,'click',function(){ callback(elT.value) });
      	}
      	Run.addEve(elB,'click',zap);
      	Run.addEve(elB2,'click',zap);
      	document.body.appendChild(elDiv);
      	elT.focus();
      }
      // test case- arguments: prompt text, default input, callback function

      Run.prompter('T ype a value','',funct ion(tem){alert( tem)});

      Comment

      Working...