function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
PremanathPremanath 

Problm with javascript

Hi All,

Please Help me in my issue.from last two days it's not came.

 

I wnat to open a new window when we click on a button.So popwindow came now.

But whenever we click on outside the popup window it should be close.

It can work on VF page. But i want to create javascript Button for this same issue . 

My VF page code is:

 

<apex:page >

<script type="text/javascript">

function openLookup(){

var url="/apex/LookupExamplePopup?namefield=" + name + "&idfield=" + id;
newWin=window.open(url, 'Popup','height=500,width=600,left=100,top=100,resizable=no,scrollbars=yes,toolbar=no,status=no');
if (window.focus)
{
newWin.focus();
}

return false;
}

<!-- openPopup("apex/dfsdfs","350, 480,height=480,toolbar=no,status=no,directories=no,menubar=no,resizable=yes,scrollable=no",true); -->

}
</script>

<apex:form >
<apex:commandButton onclick="openLookup();return false;" value="Show Popup"/>
</apex:form>

</apex:page>

---

The same thing should be done on Javascript button also.

 

Please help me guys,

kerwintangkerwintang

If you want to close the popup when you click outside that window, I think that javascript should be placed in the popup window.

 

In the page LookupExamplePopup, add this script:

<script>

 

window.onblur = function() { window.close(); }

</script>

 

Hope this helps!

 

PremanathPremanath

Hi thanks for your reply.

It doesn't work.

 

Please create one javascrip button with my code and cheack it out. Please find error.

 

{!REQUIRESCRIPT("/soap/ajax/8.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/15.0/apex.js")}

var url="/apex/commentspage?&id=" +" {!Contact.Id}";

newWin=window.open(url, 'Popup','height=500,width=600,left=100,top=100,resizable=yes,scrollbars=no,toolbar=no,status=no');
if (newWin.focus())
{
newWin.focus();
}
window.onblur=function()
{
newWin.close();
};
newWin.onblur=function()
{
newWin.close();
};

kerwintangkerwintang

You need to put the javascript code in your popup window, not in your opener window.

 

In the script you posted, the url = "/apex/commentspage?&id="....

 

so open the commentspage visualforce page, then add the script there:

 

<script>

window.onblur=function(){ window.close();};

</script>

 

I just tried it out and it's working :) hope this will resolve your problem.

PremanathPremanath

Thanks for your reply but it's not working ...

When we click on another tab it's working.

when we click on same window the popup doesn't close.

 

 

kerwintangkerwintang

Maybe i am not understanding your requirement correctly..

 

Do you want to open a new popup window, and in that  popup window, whenever the user clicks outside the popup window (i.e. loses focus), you want to close the popup window. is that correct?

PremanathPremanath

Yes your right,

 

The popup window should be close when we click on outside of that popup window.

But your and my code working only when we click on outside of overall page means when we click on another Tab.

 

Please check it out.

kerwintangkerwintang

Is there a javascript error? If so, what's the error?

PremanathPremanath

There is no error but it just not working..

kerwintangkerwintang

Can you also post the code for commentspage VF page?

PremanathPremanath

<apex:page standardController="Comments__c">
<script>
window.onblur=function(){ window.close();};
</script>
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:inputField value="{!Comments__c.Comments_Text__c}"/><br/><br/>
</apex:pageBlockSection>
</apex:pageBlock>

</apex:form>
</apex:page>

kerwintangkerwintang

I'm trying to understand this:

 

"When we click on another tab it's working.

when we click on same window the popup doesn't close."

 

 "The popup window should be close when we click on outside of that popup window.

But your and my code working only when we click on outside of overall page means when we click on another Tab."

 

Let's say you have browser A which opens the first page.

 

In the first page, you have code to open the window:

window.open(......)

 

This will open the popup window for the VF commentspage. It will be focused automatically.

 

Here are my questions:

- In that popup window, when does the code work? When we click on the first page in browser A?

- When does it NOT work? When you click outside browser A (i.e. click on another application).

PremanathPremanath

Actually i am creating a javascript Button on Contact object.

 

setup--> contact--> buttons and links

javascript code i am writing here.

 

The code will work on when we click on button in contact record.

 

I think your right window.open we are using another tab only ...

So it works only when we click on another tab.

 

Is there any Solution....