What is causing some browsers to see my code as unsolicited?
I have a web site devoted to helping people with interactive sessions. It starts with the user clicking [Begin] so this is a consented action. This should (1) open a popup while (2) redirecting the first page to a end page as below :
<head>
<SCRIPT language="JavaScript">
function openwindow(){window.open("{INTERACTION}","interaction","resizable=0,width=800,height=600,status=0");}</SCRIPT>
</head>
<body>
<FORM action="end.php" method="{METHOD}" >
<input type="submit" class="button"
onClick="javascript: openwindow()"
value="Begin" />
</FORM>
</body>
As said, this is not trying to open an unrequested popup but some strains of IE and Chrome appear to be treating it as such. I have been trying to get a fix, most recently digesting this post.
In it Bobince comments
these days, you don't really need to ask the question “was my unsolicited popup blocked?”, because the answer is invariably “yes” — all the major browsers have the popup blocker turned on by default. Best approach is only ever to window.open() in response to a direct click, which is almost always allowed.I'm quite happy to buy into this principle because I simply want my popup to open.
What is causing some browsers to see my code as unsolicited?
I'd appreciate any help you could give me. (as you might have guessed, client side is not my bag and this topic has been bugging me for ages).
Many thanks in advance (and fingers crossed)
Giles
No much you can do. You could ask your users to disable pop-up blockers or inform them that a pop-up blocker is enabled by checking the window object ref returned by window.open()
e.g.
var w = window.open('http://domain.com');
if(!w) {
//an alert in this example
alert('oops..seems like a pop-up blocker is enabled. Please disable');
}
you could find another way and try what Brad suggests.
There isn't anything you can do about this. Some popup blockers still block everything, even in response to a user clicking. The best you can do is suggest your users turn off popup blockers, or find a different way to do what you want to do. A popular method is the div that appears on top of all others on your page, like Lightbox.
There are many jQuery plugins which make this easy.
You have (at least?) 2 options to deal with this:
if you want to keep using popups, display a very visible warning for your users, pointing them to instructions on how to configure their browser to whitelist your domain (like the banners that appear on top of StackOverlow.com when you gain new privileges, or even like the banners Chrome is showing for actions - they are web-based as well);
use an iFrame and load its content based on your user's click.
Related
I have a form I like to open in pop up windows when user close my website or browser .. I want like to take feedback from users by pop up form like "give your comments how we can improve our website" and then with php I will submit the form and admin of website will get users feedback.
I am stuck here and fail to find JS code that open popup form on close browser event.
can any one help me out.
Stop wanting to do that. Imagine how horrible the user experience would be for the whole web if it were possible to do that. If it was already possible, a rampaging mob with flaming torches and pitchforks would demand it be fixed immediately. Be thankful that there is no satisfactory answer to your question.
What have you tried so far?
Here is one approach, but user may be able to disable it, and may be blocked by popup blockers (not to mention a whole ethics debate, but hey... you asked):
From main page:
<script>
window.onbeforeunload = function()
{
var url = "feedback_form.html";
window.open(url, "_blank", "toolbar=yes, scrollbars=yes, resizable=yes, top=500, left=500, width=400, height=400");
};
</script>
Confirmed that this code works in IE9, Chrome, and Firefox with the popup blocker disabled.
Usability concerns and other thoughts:
This will usually annoy people and is considered evil.
This approach relies on popup blocker being disabled (if using a browser that supports it)
Feedback is voluntary when sourcing from a crowd (your users) like this. Therefore you should make it more of an option. Many sites do a side-floater or hyperlink for "Add your Feedback" or whatever. I would recommend going this route instead of relying on closing the browser.
This code will fire on closing the browser, but will also fire whenever user leaves the page, including POSTing form data and navigation to other pages on your site.
One interesting application for this could be to send some metrics to your server via an AJAX call on window close instead (like recording how long user visited page, what actions they performed, etc.) that could be used in addition to the voluntary feedback form to learn more about what your users are doing on the site.
It is not uncommon for enterprise intranet web applications to do stuff like this (manipulate browser windows), and often those sites / domains will be added to the trusted sites for the client computer, which may include disabling the popup blocker.
I would like to make a bookmarklet to open google chrome's settings panel and clear my cache with a single click.
For a while now, Ive had a bookmark that opens chrome's settings panel with the 'clear cache' setting already selected. After clicking the bookmark (normally opening it in a new tab) I have to then opent the tab and submit the form. However, when developing this is a task I have to do quite often and these several repeated steps just seem unnecessary.
This link opens the page to clear one's cache (obviously for Chrome users only): chrome://chrome/settings/clearBrowserData#cache
I recently discovered bookmarklets and thought it would be a good way to accomplish the task of clearing my cache with a single click. However, I've discovered that putting even a basic javascript sample in the address bar when on the settings page (linked above) fails to work.
For example, this works in the address bar on any given page, but not from the chrome settings page:
javascript:alert('hello stackoverflow');
Is there a way to execute javascript from the chrome settings page? Are there other options? Im looking for any route to achieve this goal and would love to learn something along the way, even if it means doing some evil. :)
add a bookmark:
javascript:document.write('<form onsubmit="window.open(\'javascript:\'+js_line.value, \'target\');return false;">javascript:<input type=text name=js_line style="width:90%;"/></form><iframe src="" name="target" style="width:100%;height:90%;"/>');
What you want might not be fully possible through a bookmarklet, but it's certainly possible with a Chrome App. There is an app Clear Cache already. I find it pretty useful.
I am doing a web site for someone who swears the way his old site worked was that when a user clicked on a specific link, the link would open up multiple browser windows with each going to a different destination.
Specifically, the link would say something like "compare prices" and clicking the link would open up a new window for Amazon.com, Bargains.com, and Overstock.com.
I do not believe I have ever seen this done without the use of JavaScript, like porn sites used to do (and maybe they still do but I don't visit them). And didn't most browsers implement measures to stop multiple windows from opening at once?
Can you tell me whether this can be done and should it be done?
http://www.webdeveloper.com/forum/showthread.php?t=72649 This not also has the answers to your question but also good opinions on why its not great to have this action in place :)
You can do it client-side:
$('#link-id').click(function(e){
e.preventDefault();
window.open('http://www.google.com');
window.open('http://www.yahoo.com');
window.open('http://www.msn.com');
});
Check this fiddle.
I would like to create a webpage with browser specific in javascript.
For example:
can I use code like this in my coding part
chrome.tab.onRemoved.addListener() in my webpage.
If it is possible please suggest me.
What exactly are you tring to acheive?
If you want to know when the tab in which your webpage is loaded is closed, then window.onunload should help you.
If you want to know when another webpage is closed, you cannot do this.
UPDATE:
You said that you want to know when the user closes the browser or tab. This is not possible.
But for your purpose (getting feedback), I think all you need is to differentiate whether the user is navigating to a link in your page, or whether the user is typing another URL(or by clicking a favorite).
I think for your requirement, whether the user closes the browser, or whether he types another URL, is the same - the user is navigating away from your site, and at that time you say you want to collect feedback.
This can be done in javascript.
For all the clicks in your page that
might lead to a page refresh
(hyperlinks, buttons,...), set a flag.
In window.onunload, check whether
this flag is set.
- If it is set, then
the user has clicked a link in your
page, do nothing.
- If the flag is not
set then the user is navigating away,
time to collect feedback.
Let me know if this would work.
PS: Note that popups/any distractions during window.unload can be very annoying.
I understand that this probably is the requirements given to you. But if possible, try other mechanisms to collect (voluntary) feedback from the user.
No, you cannot access extension-specific APIs from webpages.
The Navigator object contains all information about the visitor's browser.
https://developer.mozilla.org/en-US/docs/Web/API/Window.navigator
I think this is pretty much the extent of what is possible in terms of interacting with the specific browser. You can't access other tabs (for security reasons) or tell when a tab is closed.
You can use use the onbeforeunload event:
<html>
<head>
<script>
var exit = 1;
function handleClose()
{
if (exit)
{
alert("Closing");
}
}
</script>
</head>
<body onbeforeunload="handleClose()">
Navigate to other page
</body>
</html>
I want to have a link or something which could be inserted in an email/forum etc. It's a typical url. But I would like that link to be opened in a custom sized new browser window ( say 800 x 600 ) . It sounds weird, but that is the requirement. Can it be achieved somehow?
Thanks
In an email?
You can't. Email clients insane enough to execute JavaScript are all by unheard of.
In a forum?
Assuming you aren't the administrator of it, you can't. Forums insane enough to encourage XSS attacks are, again, all but unheard of.
Ok. This is how we could kinda achieve this. Let that link be a normal link. It would contain the custom code to create a desired popup on invocation. But the issue is popup blocker in browser. But they somehow liked it.So basically a page opens up which launches the popup without user interference.