How to open webpages in a new tab in internet explorer? - javascript

In my html code there are several link like this:
example
Is there a way to open these links in a new tab ( and not in a new window ) ?

You cannot control the preference the user has set in their browser. You might consider adding some text like
"Hold down the Ctrl key and click the following link"
If the user follows your suggestion, the page will open in a new tab. None of this is optimal.
See HTML: how to force open links in a new tab for more.

target="_blank" attribute should open that page in a new tab. It probably depends on your browser settings whether the page opens in a new tab or window.

There is no way to do this, short of a browser plugin.
That is for a reason. You do not want to take the user somewhere they don't want to be.
They may not want to be in Internet Explorer.
What you SHOULD do is suggest that your website may only be compatible with IE. This way, the user can only blame themselves if something does not work. Not ideal, but it's generally accepted practice.

Related

How can I delay a new tab from loading with a userscript?

I use a userscript to modify the client-side code of a website. This code is adding an anchor tag to the page. Its target is _blank. The thing is that if I click this link too frequently, the site errors. A simple refresh on the new tab fixes the problem.
When I click on the link and it instantly opens a new tab. But I don't want that new tab to render until I visit it, or with some sort of time delay. Is there a way of achieving this?
I am using Firefox, so Firefox-only solutions are fine. I found this, but I don't see a way of using it to prevent the tab from rendering in the first place. When I Google for this, I see results about add-ons that can solve the problem. But, the links to them always 404. Ideally, the solution would only affect the tabs created by this script instead of the way all tabs work, but if the only way to do it is to affect the way all tabs work, I'd accept that as a solution.
The Tampermonkey documentation says there is a GM_openInTab function. It has a parameter called loadInBackground, but it only decides if the new tab is focused when you click the link.
If there is a way of making this new tab render some HTML of my choosing, I think that would be a neat solution. i.e., I'd write some HTML that, on focus, goes to the actual website's page. If this is an option, I'd need to know how to open a tab to HTML of my choosing in grease monkey.
(Just realization of idea you told in your question yourself)
You can place simple page that waits for focus and then redirects to what you pass in URL parameter somewhere and open in background tabs. Like:
load-url-from-search-on-focus.html?http://example.com:
<!doctype html>
<body
onload="document.title=u=location.search.slice(1)"
onfocus="u?document.location.replace(u):document.write('?search missing')">
Try it.
(data:uri could have been used instead of hosted page, if there weren't those pesky security precautions blocking rendering of top-level datauri navigations :|)

Google chrome doesn't open multiple mail clients

I have the following code in which I am trying to open multiple mailclient
It works in Firefox but dont work in Chrome
<button class="button">Open Email</button>
$(document).ready(function(){
$('.button').on('click',function(){
window.location.href = "mailto:user#example.com?subject=Subject&body=message%20goes%20here";
window.location.href = "mailto:user#example.com?subject=Subject2&body=message%20goes%20here";
});
});
Here is the fiddle to it
Anyone knows whats the reason behind this , or is there any other technique to do this?
Thanks
Chrome allows only one opened window per user action. If opening new browsers window was the issue, you could tell the popup blocker to allow it, but this is not possible when launching email windows. You could either require two user actions (e.g. two buttons) or you could make a web based mail form to do the same thing (if you're using the mail client of tracing purposes, just make it send a copy to yourself.
If you want to open multiple links you shouldn't use window.location.href, it opens link in current window and you cant really have more than one link opened in one window. You should use window.open(your_url) for that, but beware, it will create popup windows.
From a browser perspective mailto is a link like any other, so assigning it to window.location.href twice in a row is like fast-clicking two links in a page, browser will process only one of them.
And the last, code from your question not working even in FF if you use browser based mail client, like gmail.
You could supply 2 links for the user tp open the email clients manually, you could also open the client, refresh the page (indicating something on the url for the second one) and then open the second one?

chrome.extension.getViews() and Extension Options page

If I open a new tab and navigate to chrome-extension://{ext_id}/options.html by typing directly into the address bar the page shows up in the list when I do
chrome.extension.getViews({'tab'})
This is the expected behaviour.
If I [right click] on my extensions "browser_action" action and select "Options" this brings up a new tab with chrome-extension://{ext_id}/options.html as the URL and it shows up in the list when I do
chrome.extension.getViews({'tab'})
Again, this is the expected behavior.
If I click a link on my extensions popup, that navigates to the options page, this opens up a new tab and navigates me to chrome-extension://{ext_id}/options.html. This is the expected behavior.
BUT, there is always a but, for some reason this page does NOT show up in
chrome.extension.getViews({'tab'})
Even though it is obviously within the context and protocol of the extension. I just don't know what the difference between the FIRST and the LAST scenario is. If anything I would expect the first scenario to fail since the user is manually navigating there, rather than a extensions own popup navigating to the extensions own options page.
I have tried using both
<a href="options.html" target="_blank">
/* and */
<a id="options" target="_blank">
<script>
document.getElementById('options').href = chrome.extension.getURL('options.html');
</script>
/* This correctly sets the href as chrome-extension://{ext_id}/options.html */
but again the same problem. The extension still runs all its Javascript correctly. I still am able to use chrome.extension functionality correctly. Just the page is not showing up within getViews. I suspect it is a Sandboxing issue, but I can't understand it working for all other situations expect one.
Does anyone know how to either get it to work correctly? or open up the page in a different manner so it will work?
PS: I do not wish to open up the options page within the popup window. I have tested this, and it STILL does not list the page within the getViews but I presume this is because it is no longer a 'tab' but a 'popup'.. But again, its not the behavior I wish.
If it looks like a bug and feels like a bug, then it is probably a bug. In the future, if you think that you're experiencing a bug, don't hesitate reporting it on Chromium's bug tracker at http://crbug.com/new.
I have reported your bug as https://code.google.com/p/chromium/issues/detail?id=341459.
A work-around to get your extension page opened from the popup window to show up in chrome.extensions.getView({type: 'tab'}) is to open the tab using chrome.tabs.create:
chrome.tabs.create({
url: 'options.html'
});

How to identify browser tab?

I would like to identify browser tabs (on my domain) using JavaScript.
I mean that if user open several tabs with my website and submit web form only on one page I want to notify only this page, even if user moves from this page.
It should be max cross browsers solution.
P.S. One of the possible solutions is using "window.name" property, but I do not want to use it because somebody else can use it.
P.S-2: I found one more possible solution: using sessionStorage. It supported by FF3.5+, Chrome4+, Safari4+, Opera10.5+, and IE8+. Oooohhh, I need IE7!!!!
Thank you in advance!
I don't think this can be done. Each browser tab that is opened is basically like a new browser instance. Just like if the user opened another browser. One tab knows nothing about the other tab by design. This is how it should be. Can you imagine the implications if a web site developer could add code to their page to "see" what other sites you have opened in your browser?
window.name is the only persistent data element you can use for this purpose, as described your requirements.
I want to notify only this page, even if user moves from this page.
This is impossible. Once a user navigates away from a page, you lose control over that tab. You can't push to a page, it needs to make a server request FROM that page, even if it's ajax.
Using sessionStorage. It supported by FF3.5+, Chrome4+, Safari4+, Opera10.5+, and IE8+.
For IE7 using "window.name" property.

Javascript for removing menu and scroll bars

I have this script on my html page:
<script language='javascript'>parent.resizeTo(550,510);</script>
I'd like to add to it so it positions the window in the middle of the screen. Also, I want to remove the address and tool bars (I've managed to hide the scrollbars by using body{overflow:hidden;}).
I know how to do this using JS upon opening a new window from the browser but this needs to work from clicking a link on a PDF.
Does anyone have any suggestions? Thank you!
You can't remove address bars, etc. from the user's browser window (even if the user is only you) unless you create a new window object. And the trend is toward removing more and more of your ability to "customize" such popup windows, for security reasons.
This is actually a feature, not a bug. Think about it.
If you're opening a browser window from a separate application, the page starts off its life with a completely-decorated browser window. There's no way to make those decorations go away after the page is loaded.
While I seriously doubt the justification of your desires the way to do it is to somehow open a window. That means that your pdf links to a page that as its action will open a window with an url that has the actual content. The pdf links to a page that is basically a redirector. You give the final URL as a parameter and launch it. Of course you need to disable the popup blocker for this to work, but you should not even consider doing this on a public (no browser control) website anyway. You also might want to add to the redirector page a button that the user can click to open the page if it was blocked by the popup blocker.

Categories