I am developing an application with ASP.net and VB.net. In that application i have written this simple javascript function in the popup window in order to refresh the parent window when the popup is closed.
function RefreshParent() {
if (window.opener != null && !window.opener.closed) {
window.opener.location.reload();
}
}
window.onbeforeunload = RefreshParent;
This was working fine. But suddenly it stopped working. Its still working on Firefox and internet explorer.
its not just a problem in my PC. I am getting this problem from every user who is using chrome to access the application.
The function was working fine. Its just stopped working suddenly. And I can assure that there was no such changes been made which might cause this happen. Its still working on Firefox and IE
But i Have tried the following to see if the problem is related with chrome settings
to see if the javascript is enable or not I double checked the content settings section in advance setting of the browser. Allow all site to run Javascript option is selected.
And I have also re installed chrome.
According to the suggestion of Jeremy I have added two alerts in the javascript function to see if the function is accessed or not.
function RefreshParent() {
alert("Accessed the function!");
if (window.opener != null && !window.opener.closed) {
window.opener.location.reload();
}
}
alert("refreshed parent window!");
window.onbeforeunload = RefreshParent;
I can only see the 2nd alert. But this alert comes when i click to open the popup.
Also when I add this two alert the refreshing function also stops working in firefox (I did not checked in ie with the alert on.)
How to solve the problem
The following solution works for me. In POPUP.vb.aspx POPUP page I added the following line of code under button click
Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "refresh", "var url = window.opener.location.href; window.opener.location.href = url;", True)
Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "CloseWindowScript", "window.close();", True)
I still have the javascript function ( mentioned in the question) in the asp.net page. Its not clear why its suddenly just stopped working in Chrome.
Related
I am trying to send data to a popup window which opens by clicking a button.
All my code is in php where I include javascript and html, I will just show html and js here.
Consider my popup window (say, popupwindow.html) code as just
<div id = 'getData'></div>
Now on the page(say, main.js) where I put the button clicking which the popup opens, I am computing some data and trying to send it to popupwindow.html.
Here is relevant main.js code that gets executed after clicking the button
var popup = window.open("popupwindow.html", "popup", extraParams); //ignore extraParams
$(popup).on('load', function() {
//console.log("inside onload function");
popup.document.getElementById("getData").innerHTML = data; //here data is some string
});
Now this code works perfectly on Chrome and Firefox, but in IE load() function does not get executed. I know this because the console.log line when uncommented, does not print on the console. Tried versions of jQuery from 1.2.3 to 2.2.1 where the code runs successfully on Chrome and Firefox(but not in IE)
Note: I cannot execute the required code on popup page(popupwindow.html) because of some constraints. I have to write it on main.js and send it to popup.
I saw all other questions which said onload() or similar function in IE gives problems but I still could not find the appropriate solution. Please let me know how I can fix this for IE.
This is kind of strange issue i am facing, below is my simple code
<script type="text/javascript">
function openMyWindow() {
var formid=document.getElementById('myForm');
window.open('https://test.com','POPUPWINDO','left=443,top=107,width=650,height=650,location=0,toolbar=0,statusbar=0,menubar=0,scrollbars=0,resizable=0');
formid.method = 'post';
formid.target = 'myWindow';
formid.action = 'https://test.com';
formid.submit()
}
this is working in my local ie11 and chrome. Server chrome it is working however IE11 it is not working. Tried almost everything . I debugged this code using ie debugger found that one window opens at window.open and another Tab opens at submit()
Yes, as the name suggests, I am getting two print dialogs on Chrome latest and FF latest.
The code I'm using is:
var $printButton = $('#print_button');
if ($printButton) {
$printButton.on('click', function () {
window.print();
})
}
The second dialog only opens when I have actioned the first dialog (print or cancel), if that helps.
EDIT:
After narrowing it down to an issue with my callback, I put a console.log('hello'); in the script and found that it was calling twice on refresh.
My script file was being included twice somewhere on the page. Thank you legacy code :)
Thanks for the advice everyone.
Having issues getting my one page web application to work in Internet Explorer and Edge. It works perfectly fine in other browsers.
The issue that I'm having is that I can't seem to get the navigation to work.
I've tried the following:
location.href = '#quickQuiz'
location.href = '/#quickQuiz'
window.location.href = '#quickQuiz'
window.location.href = '/#quickQuiz'
document.location.href = '/#quickQuiz'
document.location.href = '#quickQuiz'
function goHere(where) { window.location = where; return false; }
location.hash = '#quickQuiz'
location.hash = '/#quickQuiz'
All of them works perfectly fine on other browsers. What am I doing wrong?
http://www.snabbteori.se if you wanna see it for yourself.
EDIT1: Additional code
The item in my navigation menu looks like the following:
<li data-icon="info"><a id="teoriNav">Teori</a></li>
And then I check for a click event on it. I know that it's possible to just put href="#teori in there, but I am just using this one as an example, there are other links where I need to perform AJAX calls too, this one doesn't need it though just to verify there isn't something wrong with my AJAX calls causing it.
$(document).delegate('#teoriNav', 'click', function () {
location.hash('#teori');');
});
I've also tried this but doesn't work:
$('#teoriNav').click( function() {
location.hash('#teori');
});
EDIT2: Updates
I believe I've fixed all jQuery errors and some other issues. The only thing I'm getting in the Internet Explorer console is:
HTML1300: Navigation occured.
DOM7011: The code on this page disabled back and forward caching.
And then when I click on the button I get output which I wrote which confirms it registers my click on the button. But still it won't navigate.
EDIT3: Ugly temporary fix
It works after doing a page reload after navigating.
var isIE = /*#cc_on!#*/false || !!document.documentMode;
var isEdge = !isIE && !!window.StyleMedia;
if(isEdge || isIE)
location.reload();
But I hate the fact that the site has to reload, and if someone has a real fix for this I would really appreciate it...
Edge has an issue with links if your code is not propper. You should check your console for any errors, This is most likely.
We will need more information from your side to help you further.
Post your HTML and your Javascript (just relating to this area of problem)
and we can then better help you.
I sagest fixing your jQuery errors first and trying again.
Ok my Browser test have given me a variation of 30-60 error relating to jQuery across Mac to Win. These will need to be addressed.
You also have a XSS issue that needs to be resolved. You have HTTPS from facebook but then HTTP on your website, These will need to match.
I can't seem to figure out why the following simple popup will not work in IE9. FF & Chrome popup as expected, but IE does not appear to do anything when the link is clicked. I tried the IE9 debugger, but didn't get any helpful information out of it.
In the head section:
<script type="text/javascript" language="JavaScript">
function JSPopup(linkref) {
window.open(linkref,"Report Definitions","width=600,height=480");
return false;
}
In the body:
<strong>Report Definitions</strong>
Thanks for your help,
Filip
Turns out the problem was the name given to the popup - IE doesn't allow spaces, FF & Chrome do:
window.open(linkref,"Report Definitions","width=600,height=480");
needed to be changed to:
window.open(linkref,"ReportDefinitions","width=600,height=480");
This works across browsers.
Filip
This is part of the security changes made in IE6. Now you can only call "window.open" from within a user-initiated event. For example, your code would work inside an element's onclick event. The "window.open" http://msdn.microsoft.com/en-us/library/ms536651(VS.85).aspx MSDN page says this:
"This method must use a user-initiated action, such as clicking on a link or tabbing to a link and pressing enter, to open a pop-up window. The Pop-up Blocker feature in Internet Explorer 6 blocks windows that are opened without being initiated by the user."
Example...
function popUpWin(url,wtitle,wprop){
if (!window.open){ return; } // checking if we can't do this basic function
// Kill if(win), since win was a local var this was a usless check
var win = window.open(url,wtitle,wprop);
// next line important in case you open multiple with the same 'wtitle'
// to make sure the window is reused and refocused.
if (win && win.focus){ win.focus(); }
return false;
}