1

I need to by pass an IE confirm 'OK'/'Cancel' pop-up message. I have a problem running a JavaScript function in my VBA script. My JavaScript:

 function ConfirmSave()
{
var Ok = confirm('Are you sure all Documents and Information are attached and correct before saving?');

if(Ok)
return true;
else
return false;
}


function submitbutton_click() {
    document.getElementById('FileAttachement2_hdnButtonFlag').value = "SAVE";
    var submitbutton = document.getElementById('cmdDownSave');
    var uploadobj=document.getElementById('FileAttachement2_Uploader1');
    if(!window.filesuploaded)
    {
       if (!ConfirmSave()) return false;
        if(uploadobj.getqueuecount()>0)
        {

            uploadobj.startupload();
        }
        else
        {
            //var uploadedcount=parseInt(submitbutton.getAttribute("itemcount"))||0;
            //if(uploadedcount>0)
            //{
                return true;
            //}
            //alert("Please browse files for upload");
        }
        return false;
    }
    window.filesuploaded=false;
    return true;
}

In manual process, when I click the save button, the page will pop-up a confirm message box, and my macro will stop running when the pop-up appears unless it has been clicked.

Here is the code I have tried, to click the save button,

Set ElementNameV = HTMLDoc.getElementsByName("cmdsave")
ElementNameV(0).click

I also tried using removeattribute and setattribute with which the pop-up message disappeared but it doesn't upload the file because I need to press the 'OK' in confirm message box that will appear upon clicking the save button to start the file uploading.

ElementNameV(0).removeAttribute ("onclick")
ElementNameV(0).setAttribute "onclick", "return true"
ElementNameV(0).click

I tried running the JavaScript function using below script but it also shows the confirm pop-up message box:

Call HTMLDoc.parentWindow.execScript("submitbutton_click()")
8
  • May I ask why you aren't using the native VBA/VBScript methods? Commented May 14, 2015 at 2:21
  • @BryanC. what do u mean by native VBA methods? can you share some suggestions on how do I able to control the pop-up confirm message when it appears? because my codes stop running when I click the save button and the pop-up appears Commented May 14, 2015 at 2:25
  • Take a look at this page... this is a VBScript OK/Cancel message box: stackoverflow.com/questions/3062401/… see selected answer at the top. Commented May 14, 2015 at 2:27
  • This may or may not be useful depending on what you're doing. Commented May 14, 2015 at 2:35
  • that's not what I am looking for, I do not need to create a pop-up message. what I need is to handle the pop-up message that will appear when my I click the save button from a web page. Commented May 14, 2015 at 2:36

2 Answers 2

4

You should be able to overwrite the ConfirmSave function with one which simply returns true:

HTMLDoc.parentWindow.execScript "window.ConfirmSave = function(){return true;};"

or

HTMLDoc.parentWindow.execScript "window.confirm = function(){return true;};"

or even

HTMLDoc.parentWindow.eval "window.confirm = function(){return true;};"

Run that before clicking the button.

Tested and works in IE11

Sign up to request clarification or add additional context in comments.

17 Comments

btw, how can I Run this using IE11? because I think this code works only in old version of IE?
It works with my friend using IE9 but it doesn't work with me using IE11. do you have any idea?
meaning, it works with IE version 9. but in IE ver 11, nothing happens when the code runs.
See my edit above. Both suggestions tested and working in IE11
It doesnt worked for me, I don't know why, but I think it has something to do with this execScript is no longer supported. Starting with Internet Explorer 11
|
-1

So I've read your question a few times now and I think that to achieve what you want to do you are going to have to completely change your approach to the problem. You need to read up on Javascript Concurency, Javascript Web Workers, and the Javascript Event Loop.

Just throw these terms into Google and you'll find lots of great resources to learn about this.

By default Javascript is a single threaded language and it halts while waiting for events to complete their activities. What you seem to be looking for based on how I'm reading your question is a way for your Javascript to keep performing actions while a user prompt is being displayed.

While this is not an endorsement, I will throw out this one link to get you started.

2 Comments

my automation is written in VBA script. not javascript, I just need to interact with javascript to run my macro. but then, I will take a look with those Javascript Concurency, Javascript Web Workers, and the Javascript Event Loop
You know what... maybe... take a look at this other question and see what you think: stackoverflow.com/questions/10008556/… and look at that top answer. Maybe that's what you're looking for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.