My scenario is in CRM after clicking on a button, it opens an external webpage (ASPX) as a popup, this webpage is simply a search page. And I want to get back the selection item in this page to update CRM page.
I'm using this code for open the dialog:
function openAddressSearch(addressType) {
searchAddressType = addressType;
//Allow for borders.
var width = window.screen.width * 2/3;
var height = window.screen.height * 2/3;
var leftPosition = (window.screen.width / 2) - ((width / 2) + 10);
//Allow for title and status bars.
var topPosition = (window.screen.height / 2) - ((height / 2) + 50);
//Open the window.
var addressSearch = window.open("http://localhost:2402/", "AddressSearch",
"status=no,height=" + height + ",width=" + width + ",resizable=yes,left=" + leftPosition + ",top=" + topPosition +
",screenX=" + leftPosition + ",screenY=" + topPosition + ",toolbar=no,menubar=no,scrollbars=yes,location=no,directories=no");
/* addressSearch.callback = function (result) {
alert(result);
}*/
if (window.focus) {
addressSearch.focus();
}
}
function addressSearchResult(result) {
alert(result);
}
In the webpage (aspx), on selection button click, I call to a js function:
<script type="text/javascript">
myClosure = function () {
window.opener.addressSearchResult("CALLBACK");
window.close();
}
</script>
<asp:Button runat="server" ID="m_btnSelect" Text="<%$ Resources: myResource, Select %>" OnClientClick="myClosure();"/>
But once clicking btnSelect, I got error at line:
window.opener.addressSearchResult("CALLBACK");
SCRIPT70: Permission denied
localhost:2402, line 11 character 13
What should I do to pass this error and send back result to the opener?
You can using eventListner, in your openAddressSearch, add following event listener to current window:
window.addEventListener("message", function (result) {
alert("CALLBACK");
});
In the your external webpage:
window.opener.postMessage(address, "yourParentPageUrl");
Hope this helps.
Related
window.open not working in iphone at the time of document ready event
I have write the code to open the new windows at the time of page load event. this event working fine in evenry browser instead of iphone(Safari). now i dont know what the alternative way to do this?
please help me to solve this issue.
OpenWindow('http://www.google.com', 800, 600, true);
function OpenWindow(query, w, h, scroll) {
var l = (screen.width - w) / 2;
var t = (screen.height - h) / 2;
winprops = 'resizable=1, height=' + h + ',width=' + w + ',top=' + t + ',left=' + l + 'w';
if (scroll) winprops += ',scrollbars=1';
var f = window.open(query, "_blank", winprops);
}
Here is a workaround
<script>
document.write("<a id='mylink' href='mypage.html'></a>");
document.getElementById('mylink').click();
</script>
or
<body onload="myfunct('mylink')">
and declare the function as above
I have a link on a page on clicking which I open a new window like a popup.
Now I would like the user to close it before he can go back to the old page. He should not be able to navigate to other tab before closing it. How would I do this?
<script type="text/javascript">
function popup(url) {
var width = 300;
var height = 200;
var left = (screen.width - width) / 2;
var top = (screen.height - height) / 2;
var params = 'width=' + width + ', height=' + height;
params += ', top=' + top + ', left=' + left;
params += ', directories=no';
params += ', location=no';
params += ', menubar=no';
params += ', resizable=no';
params += ', scrollbars=no';
params += ', status=no';
params += ', toolbar=no';
newwin = window.open(url, 'windowname5', params);
if (window.focus) {
newwin.focus()
}
return false;
}
</script>
Centered popup window
You should define your window as a modal window, window.showModalDialog.
Look at the following instructions showModalDialog
An alternate way is to use jQuery dialog. in this case the whole screen is blocked and user can not do anything until dialog is closed. see here
Create Close button in your popup.html page then close a window.
<input type="button" value="Close" onclick="window.close()">
thank u..
I am implemented a custom twitter button by using the following
var url = attrs.twitterShare;
var width = 575;
var height = 400;
var left = (getScreenWidth() - width) / 2;
var top = (getScreenHeight() - height) / 2;
var opts = 'status=1' + ',width=' + width + ',height=' + height + ',top=' + top + ',left=' + left;
window.open('http://twitter.com/share?original_referer=' + url, 'twitter_share', opts);
Summary, an element is clicked which calls the javascript open that opens up twitter.com/share with the url to be shared. But I wondering is there a callback I can use to get stats on the share linked such as the number of retweets?
You could embed an iframe in the popup window, which loads the share url, and when the page changes you can handle the
function callback(url) { alert(url); };
var window = open('url','name','height=300,width=300');
window.document.write('<iframe onLoad="window.opener.callback(this.contentWindow.location);" src="https://twitter.com/intent/tweet?url=http%3A%2F%2Fbbc.co.uk&text=This is a Twitter title">');
sorry if this is a repeat question!
I have the following Javascript which works fine in Firefox and produces a pop up window. In IE 9 however it does nothing at all and in Chrome it works like a link and changes the current page!
Any advice appreciated!
window.open(page,name,'width='+width+', height='+height+',location=yes,menubar=no,resizable=no,toolbar=no,scrollbars=yes');
Thanks in advance.
This is a working example
JS
function openWindow()
{
var width=668;
var height=548;
var page="http://google.com";
window.open(page, "awindow", "width="+width+",height="+height+",location=yes,scrollbars=yes, resizable=yes");
}
HTML
Open​
DEMO.
Did you create the variables correctly?
This code is working for me:
var page = 'page.php';
var name = 'pagename';
var width = 200;
var height = 100;
window.open(page,name,'width='+width+', height='+height+',location=yes,menubar=no,resizable=no,toolbar=no,scrollbars=yes');
EDIT
In my webapp I use the following function for opening windows. It should work in all browsers.
function wopen(url, name, w, h, scrollb) {
scrollb = typeof(scrollb) != 'undefined' ? scrollb : 'no';
w += 32;
h += 96;
wleft = (screen.width - w) / 2;
wtop = (screen.height - h) / 2;
var win = window.open(url, name,
'width=' + w + ', height=' + h + ', ' + 'left=' + wleft + ', top=' + wtop + ', ' +
'location=no, menubar=no, ' +
'status=no, toolbar=no, scrollbars=' + scrollb + ', resizable=yes');
// Just in case width and height are ignored
win.resizeTo(w, h);
// Just in case left and top are ignored
win.moveTo(wleft, wtop);
win.focus();
}
Where are you making the call to window.open? IE9 will block calls if they're made during page load as part of its popup blocker. Chrome does something similar, but redirects new windows to the main tab (thus, putting the user in control). As for Firefox... check your FF popup blocker settings.
I have a custom function that will open a window to the center of the screen from a different url. On my current case I am opening a url outside my domain. This is my function.
function wopen(url, name, w, h) {
w += 32;
h += 96;
wleft = (screen.width - w) / 2;
wtop = (screen.height - h) / 2;
if (wleft < 0) {
w = screen.width;
wleft = 0;
}
if (wtop < 0) {
h = screen.height;
wtop = 0;
}
var win = window.open(url,
name,
'width=' + w + ', height=' + h + ', ' +
'left=' + wleft + ', top=' + wtop + ', ' +
'location=no, menubar=no, scrollbars=yes');
// +
//'status=no, toolbar=no, scrollbars=no, resizable=yes');
win.resizeTo(w, h);
win.moveTo(wleft, wtop);
win.focus();
}
This works perfectly on IE6, and FF but not on IE7
The issue is that you are attempting to open a window with a separate domain, which in IE7 and higher is considered a security issue. Essentially, when you open that new window, it creates a new process and leaves your process separate, so you can no longer manipulate that other window.
http://social.msdn.microsoft.com/Forums/en/iewebdevelopment/thread/e9cebb92-f943-4a79-b29b-7376039ea6a0
http://msdn.microsoft.com/en-us/library/Bb250462.aspx
So, once you open that new window with a domain different from your own, you lose control of it. I don't see a way to change this without adjusting the end-users computer.
EDIT
Hmm, apparently you can get around this by opening a window that you do have control of, then changing the window.location.href to your url. Try this:
function wopen(url, name, w, h) {
w += 32;
h += 96;
wleft = (screen.width - w) / 2;
wtop = (screen.height - h) / 2;
if (wleft < 0) {
w = screen.width;
wleft = 0;
}
if (wtop < 0) {
h = screen.height;
wtop = 0;
}
var win = window.open('about:blank', // <- Note about:blank
name,
'width=' + w + ', height=' + h + ', ' +
'left=' + wleft + ', top=' + wtop + ', ' +
'location=no, menubar=no, scrollbars=yes');
// +
//'status=no, toolbar=no, scrollbars=no, resizable=yes');
win.location.href = url;
win.resizeTo(800, 150);
win.moveTo(wleft, wtop);
win.focus();
}
wopen('http://www.yahoo.com/', 'yahoo', 250, 250);
I don't know if this is a hack or not; I'm surprised it's that easy to get around, at least for changing window resize and whatnot. But, it works (at least on IE8).
there are many security things that a browser and os checks for any window.
for this case, i am not sure but try this also.
if your mouse button is clicked and hold on at the time of resizing browser window through your js code then you will get access denied error.
reason is OS denied such activities when real physical users is ready for mouse drag event.
see below url
http://prcoldfusion.blogspot.com/2012/06/access-denied-javascript-error-internet.html