You need to sign in to do that
Don't have an account?
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,
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!
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();
};
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.
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.
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?
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.
Is there a javascript error? If so, what's the error?
There is no error but it just not working..
Can you also post the code for commentspage VF page?
<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>
I'm trying to understand this:
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....