Cross-Browser compatible opening of a new tab/window (browser) - javascript

I'm sure you can help me with this issue:
I recently run into some issues with opening a new tab / pop-up on a php/javascript site.
My current solution is as followed:
<script type="text/javascript">
function Popup(url) {
window.open(url);
}
</script>
<div class="link_box">
<a class="link_box_link" href="javascript:Popup('http://www.<website>.com')"><website-name></a>
</div>
However some of my coworkers using IE6-8 can't seem to open the link. Now I hope you can help me finding the best possible and cross-browser compatible solution for opening a new tab or window. Any help or tip would be greatly appreciated!

Ok, after looking at the comments produced (mine included), I decided that I should sum it up in an answer.
The cross-browser compatible solution is simply this: (with no Javascript)
LINK TO GOOGLE
Read about it here.
There are a few reasons why this may not work:
browser settings;
pop-up blockers
About these, there isn't much you can do. Browser settings aren't editable by your script; AFAIK, there isn't a general way to circumvent pop-up blockers (and thank god for that!).
Although, there are a few workarounds that do work under specific conditions. Although, as it may be such a frustrating task to account and inquire about all those conditions with a script, my suggestion of using a modal window with an iframe still stands.
NOTE: Actually, using this should not bring that many trouble with pop-up blockers (though still possible). Note that most times pop-up blockers are triggered exactly by detecting client-side scripting to open new windows - being the method you tried possibly one of the first to trigger it.

You have to manipulate the target like Joum saved in the comment section. Or you simple are using the posible to return false;.
<a class='popup' href='www.websitename.com'>website</a>
$('a.popup').live('click', function(){
newwindow=window.open($(this).attr('href'),'','height=200,width=150');
if (window.focus) {newwindow.focus()}
return false;
});

Related

Highlighting links from websites with a browser extension

I'm looking to develop a browser extension that would recognize links from news websites and display that articles' content in a popup screen upon a mouseover. The problem is, I have no idea where to start. I have past experience in HTML, CSS, and Javascript but in terms of browser extensions I'm a fish out of water. Could someone explain to me how one would go about starting something like this? Thanks!
You can create new extensions for Chrome this may be useful to you...
or refer this
I'm also an extension noob, but I know of a really good jQuery plugin for making the hover popups (tooltips).
http://jquerytools.github.io/documentation/tooltip/index.html

Edit opened HTML Page, with Javascript

I was looking into making Firefox addons, and I need some help.
Is it possible to edit an HTML page that is open in the browser with javascript?
For example:
User types in "google.com"
Addon is activated
Javascript changes contents of "google.com" to maybe say "Hello!" at the bottom.
Of course this isn't specifically what I want to do, but a push in the right direction on how to accomplish such a task would be great.
~Carpetfizz
From within a Firefox addon this is obviously possible as many extensions do this.
If you, however, simply want to modify the DOM and nothing else than I would recommend taking a look at greasemonkey. Loads of example scripts around to do this: http://userscripts.org/
And the added benefit, if written correctly they also work in Chrome and other browsers.
Yes, it is. You must find a tutorial about javascript DOM manipulation

opening a link in <body onload=""

I guess this is possible, but I don't know how.
<a rel="width[640];height[480];autostart[true];loop[true];title[Google]" class="jcepopup" href="http://www.google.nl">Aanbieding</a>
Can it be done linke this?
<body onload="javascript: laden()">
<script type="text/javascript">
function laden()
{
window.open('http://www.google.nl rel="width[640];height[480];autostart[true];loop[true];title[Google]" class="jcepopup"', 'blablabla', 'width=720', 'heigt=500');
}
Most browsers these days block pop-ups because of this very use. There are a couple of generally accepted ways to get around this (I hope lightning does not strike me down).
Open the pop-up after the user clicks on something
Embed some Flash and use ActionScript to open it
The Flash method is renowned enough that you can find several links about it online. If you can shove some Javascript into some container, you can essentially bypass the restrictions (if you get creative). Windows Media files, for instance. Movies are great for opening pop-ups.
I'm going to leave this intentionally vague, as I don't want to be responsible for the proliferation of more pop-ups.
Yes, but you don't need the javascript: in your onload, you can just do:
<body onload="laden();">

Hiding toolbar / status bar with javascript in CURRENT browser window?

Is there some way to hide the browser toolbar / statusbar etc in current window via javascript? I know I can do it in a popup with window.open() but I need to do it this way. Is it possible at all?
As per the previous answer, this isn't possible to my knowledge and is best avoided anyway. Even if a solution can be found, bear in mind that most browsers these days allow the user to prevent Javascript from interfering with their browser settings and window chrome, even when using window.open. So you've got absolutely no way of guarenteeing the behaviour that you're looking for and consequently you're best off forgetting about it altogether. Let the user decide how they want their window configured.
I believe this is not possible. And anyway, just don't do it. Your page can do what it wants with the rendering area, but the rest of the browser belongs to the user and websites have no business messing with it.
Marijn: ok thanks. This is for an intranet site and we display InfoPath forms as separate, no-toolbar, no-statusbar windows. This is a client requirement, I'm not trying to do evil ;)
To Martin Meredith, Luke, Marijn: thanks for your quick reply. It is now settled that it's not possible.
I agree with you all about this being an undesirable behavior, but as i stated before, this is for a bank intranet application where all users are running a tightly controlled, centrally-configured, customized and hacked to death browser they have no control over anyway, and the client actually wants this behavior for the application. It would be dumb and annoying to do this in a public facing/general website, of course. But sometimes we just have to get the job done :(
No. This would be a massive security hole if it were possible... not to mention annoying.
My browser wont even let you do this in popups... which can be annoying aswell!
You may want to investigate using an HTA (HTML Application).
It will render HTML pages with zero browser chrome, a custom icon can be shown on the task bar, and the entire "caption" can be removed. The last option yields a floating window without eve a close button.
For how I imagine your needs to be, you would want to start with something like:
<html>
<head>
<title>HTA Demonstration</title>
<hta:application innerborder="no" icon="magnify.exe" />
</head>
<body style="overflow: hidden; margin: 0;">
<iframe src="http://www.yahoo.com" style="width: 100%; height: 100%;"></iframe>
</body>
</html>
Save the above HTML into a file and give it "example.hta" as the file name. You'll then have a generic icon on your desktop which you can double click on to start.
<hta:application innerborder="no" caption="no" icon="magnify.exe" />
This change will remove the title bar when running the script. Press Alt-F4 to exit the script if you do this.
This will also only work with IE, however that should not be an issue on an intranet.

Changing the default title of confirm() in JavaScript?

Is it possible to modify the title of the message box the confirm() function opens in JavaScript?
I could create a modal popup box, but I would like to do this as minimalistic as possible.
I would like to do something like this:
confirm("This is the content of the message box", "Modified title");
The default title in Internet Explorer is "Windows Internet Explorer" and in Firefox it's "[JavaScript-program]." Not very informative. Though I can understand from a browser security stand point that you shouldn't be able to do this.
This is not possible, as you say, from a security stand point. The only way you could simulate it, is by creating a modeless dialog window.
There are many third-party javascript-plugins that you could use to fake this effect so you do not have to write all that code.
YES YOU CAN do it!! It's a little tricky way ; ) (it almost works on ios)
var iframe = document.createElement("IFRAME");
iframe.setAttribute("src", 'data:text/plain,');
document.documentElement.appendChild(iframe);
if(window.frames[0].window.confirm("Are you sure?")){
// what to do if answer "YES"
}else{
// what to do if answer "NO"
}
Enjoy it!
Not possible. You can however use a third party javascript library that emulates a popup window, and it will probably look better as well and be less intrusive.
You can always use a hidden div and use javascript to "popup" the div and have buttons that are like yes and or no. Pretty easy stuff to do.
You can't unfortunately. The only way is to simulate this with a window.open call.
Don't use the confirm() dialog then... easy to use a custom dialog from prototype/scriptaculous, YUI, jQuery ... there's plenty out there.
I know this is not possible for alert(), so I guess it is not possible for confirm either. Reason is security: it is not allowed for you to change it so you wouldn't present yourself as some system process or something.
Yes, this is impossible to modify the title of it. If you still want to have your own title, you can try to use other pop-up windows instead.

Categories

Resources