+ Start a Discussion
SteveSellSteveSell 

VisualForce and Javascript

Something strange happens, when I use the IE browser:

After I call this VF page in IE7 and click on the button "Konten Import"   a new window opens up, but  the PopUp window switch always behind the main page. The main page seem to reload itself.

The symptom is:

I click on <apex:CommandButton value="Konten Import" onclick="openpopup()" />

<script type="text/javascript">

function openpopup()

{

var KontenWindow = window.open('{!URLFOR($page.KontenImport)}','Konten','height=200,width=385,status=yes,scrollbars=yes,resizable=yes');

setTimeout("openpopup()",100);

KontenWindow.focus();

}

</script>

This behavior happens only on VF Page in IE Browser.

 

Thanks

Steve

Best Answer chosen by Admin (Salesforce Developers) 
harlequinharlequin

 Hi Steve,

It's because you're using a command button to generate the onclick handler, which is the same as a 'submit' button on a regular html page, so despite trapping the click, the button still goes off and submits the form.

Try using a 'non-submit' button - use the 'btn' class if you want it to look like a SF button.
<input type="button" value="Konten Import" onclick="openpopup()" class="btn" />

I'm at a bit of a loss as to why you're using 'setTimeout("openpopup()",100);' in your 'openpopup' function. This will cause a recursive loop which will open window after window. Is this your intention?

All Answers

harlequinharlequin

 Hi Steve,

It's because you're using a command button to generate the onclick handler, which is the same as a 'submit' button on a regular html page, so despite trapping the click, the button still goes off and submits the form.

Try using a 'non-submit' button - use the 'btn' class if you want it to look like a SF button.
<input type="button" value="Konten Import" onclick="openpopup()" class="btn" />

I'm at a bit of a loss as to why you're using 'setTimeout("openpopup()",100);' in your 'openpopup' function. This will cause a recursive loop which will open window after window. Is this your intention?

This was selected as the best answer
SteveSellSteveSell
 
it works perfect.
 
Answer : setTimeout("openpopup()",100); I had read this as solution. Obviously not ;-))
 
I appreciate for you help
Steve