I'm using this bit of javascript in a .NET 4.0 web application for IE8:
ClientScript.RegisterStartupScript(this.Page.GetType(), "popupOpener", "var popup=window.open('Report.aspx');popup.focus();", true);
This opens an .aspx page in a new browser tab.
However, it does not give the tab focus, which I would very much like to do. Does anyone know how to achieve this?
Not all browsers support focus, and I believe there are some bugs even among those that do.
Try to blur the window before giving it focus. It's bizarre but has worked for folks in the past.
In general:
popup_handle.blur();
popup_handle.focus();
As applies to your code:
ClientScript.RegisterStartupScript(this.Page.GetType(), "popupOpener", "var popup=window.open('Report.aspx');popup.blur();popup.focus();", true);
Related
The requirement is I get URL of excel file in webservice response. I want to open this URL in new tab/window using javascript.
window.open(url, '_blank');
doesn't work in mac safari.
I also tried creating <a> with target="_blank" and trigger click.But it didn't work with Mac safari.
Is there any way to achieve the requirement?
Open the excel file in some specific div will also serve if it is possible.
Thanks.
Do you have a popup blocker installed ? if yes then read this . Safari/Chrome have built-in pop-up blockers that stop this from working. The only javascript that is allowed to open a new window in Safari/Chrome is javascript directly attached to click handlers (and other direct user input handlers). In past versions people figured out some ways to cheat (like generating some other element -- a form or div -- and simulating user input with javascript), but newer versions are smarter about detecting this. I'd recommend re-configuring things so that you don't use a delayed pop-up -- that is the kind of thing that can generally be jarring to a user after all.
I am facing some problems in my web application I have some hidden fields, when I press f12 it will open developer tools and hidden fields are visible there, so I disabled the f12 using some javascript code snippet. But in IE if ithe javascript is not enabled then again same issue will happen.
So is there any way to enable the javascript in IE without manual settings(any programmatic way)?
You cannot enable JavaScript in any browser programmatically. That would be just stupid thing to exist.
Think about you browsing to some malicious site filled with harmful JavaScript - even though you have set your JavaScript off in your browser to prevent the harmful scripts, the malicious site could programmatically enable it again.
No thats not possible but
you could load your form-fields with some ajax
so if theres no js, the form fields are simply not there.
But that also means, that if theres no js, you dont have your correct form.
And do you really only want ie-f12-users not to see your form-fields ? what if someone uses firefox or chrome inspectors ... or just opens the source-code ? i dont get it
So, I'm trying to run on random websites, to play with the javascript psuedo-protocol.
javascript:alert("testtesttest");
And it never works. I've tried 6 websites, and I have no clue what I'm doing wrong. I've tried googling with little success. I'm using the latest version of firefox, and I have javascript enabled.
Firefox disabled it for security reasons, because people were pasting things they were told to in the address bar.
but it still works, if you trigger it from your javascript code.
And in chrome code, I found many cases, a window is initialized with this kind of protocol.
For example if you visit http://www.w3schools.com/jsref/met_win_settimeout.asp
There will be some inside windows to be opened with
javascript:"<html><body%20style='background:transparent'></body></html>"
then later on, the location.href changed to
http://www.w3schools.com/jsref/met_win_settimeout.asp
Any one knows why this kind of change happens, and why it is allowed?
Does it suggest for layer window, the location of the window can be changed to the main page?
I am adding the following javascript at runtime to open a new browser window. I know window.open is available in javascript. But it doesn't work for safari and chrome. Is there any other trick or hooking technique to achieve this.
string script= "window.open('http://www.w3schools.com','_blank','toolbar=yes,location=yes,directories=no,status=1,menubar=yes,scrollbars=yes,resizable=no,copyhistory=yes,left=20,top=20,width=600,height=550');";
ScriptManager.RegisterStartupScript(this, this.GetType(), "newWindowScript", script, true);
Thanks
window.open() most certainly works in Safari and Chrome, I used it today! The demos on the w3Schools site work in Chrome
Try moving the code into a standard in-page <script> block (obviously with the .net stuff removed) to test and see if you get any errors in the console.
It could be that one of the features you are passing as the 3rd argument to .open() is breaking things (like the copyhistory feature - I never saw that before, and it isn't listed in the available options on the w3Schools site)? I have noticed that Chrome tends to ignore the width and open it to whatever size it wants to...
This is because of the popup blocker in the browser. You can use Ajax Modal Popup window instead of Window.Open
http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/ModalPopup/ModalPopup.aspx
Another option is Jquery popup
http://yensdesign.com/2008/09/how-to-create-a-stunning-and-smooth-popup-using-jquery/
if you still need to use Window.Open then please refer this
Bypass popup blocker on window.open when JQuery event.preventDefault() is set
I'm using IE8 in Windows7. When in Javascript I do window.open(....), the new window starts blinking in the taskbar. I want the new window to be displayed to the user and not hide in the taskbar.
I've tried:
var myWindow = window.open(.....);
myWindow.focus();
But still it starts blinking in the taskbar. Anyone knows the trick to fix this?
If there were a way to do what you want to do, every popup ad in the world would use it and the web would be a worse place. so there isn't a way to do it. =)
You might have better luck if the window.open occurs in a click handler or something like it - there are complicated heuristics baked into the browser around allowing poups if they're deemed 'intentional'.
I actually got this working. Initially I was opening IE8 using the IE icon on the task bar menu. For some reason I then decided to open IE directly from C:/Program Files/Internet Explorer/ and it worked as expected.