Detect when user wants to open the in a new window/tab - javascript

I'm writing an AJAX application so every link on my page is a javascript link (href="javascript:void(blahblah)"). Some of them opens small webpages in an iframe in a boxed, absolutely positioned div element (that can be dragged around).
This looks nice but if the user middle click on the link he can't open the page in a new tab, because the browser tries to execute the script on a new page which fails.
So what I want to do is:
If the user clicks on the link it opens a webpage in an iframe in an absolutely positioned div. (this works currently).
If the user middle clicks these links (or somehow opens the link in a new tab/window etc.) the page should load in the new tab/window as expected.
Optional: middle click should do nothing on all other javascript links.
Is there a (preferably cross browser) way to accomplish this?
EDIT: this web app is a browser game which uses the canvas element to render the game world, so I don't mind if your solution works only in canvas-capable browsers.

Is there a (preferably cross browser) way to accomplish this?
Yes, don't do href="javascript:void(blahblah)", build on things that work.

Check out the hijax technique, which allows you to progressively enhance your application to use either regular or JavaScript links. There's an hijax jQuery plugin that can help.

Related

Is there a way of exiting Google Translate's iframe?

In our website we have a link that allows people to view the page using Google Translate, e.g. https://translate.google.com/translate?sl=auto&tl=fr&js=n&prev=_t&ie=UTF-8&layout=2&eotf=1&u=http%3A%2F%2Fwww.example.com. Google Translate wraps our page in an iframe and does its magic.
We open this link in a new tab. Once the user has finished we'd like to provide an easy way for the user to get back to what they were doing. They can close the tab themselves, but their focus is on the content rather than on browser controls. Is there any way for us to provide a button on the page that will close the tab? I'm thinking something like window.close() would do for a normal tab.

How can i open a child window in Chrome when we click the custom formula link in IE

I am having a Proposal Builder Custom Formula(TEXT) using hyperlink on opportunity. When i click that i am trying to open a VF page in new window.
Hi, i need help on this salesforce task plzz.
My requirement is..
I opened Opportunity In IE and when i click Proposal Builder link on Opp, then that VF page should open in CHROME.
Any Suggestions or ideas plzzz..
Here is the Formula field i created:
HYPERLINK("https://mysalesforceorg.com/apex/cpq?opportunity_id="& Id &"&quote_id="& Id &"&Session_id="&$Api.Session_ID,"Proposal Builder","_blank")
CPQ is the VF Page to be opened when clicked.
Thankyou...
There is no way to force a browser to pass a URL to a different browser. It would be possible to create shortcuts on your desktop to open certain bookmarks in a specific browser, but what you are asking for is not possible. Once you're operating in a browser, it's going to handle any links/redirects/actions within itself (whether that be in the current tab, in a new tab, or in a new window).
With that said, there are certain extensions for Chrome that would allow an end user to render a page using an IE tab within Chrome...but there's no way for you as the developer to guarantee your users are going to do that.

How much control can a site have over links opened in a new tab?

I am creating a site which makes use of youtube videos, but I don't want to use the embedded player, I want to just have a youtube page in an IFRAME. I read the youtube TOS and I am not sure whether IFRAMES are allowed other than the embedded player so taking no chances I think I will build the site to open links in new tabs instead. What I would really like is to be able to open new links in just one tab. To clarify, my site is tab 1, once a link is clicked youtube opens in tab 2, any further links clicked on my site replace the content in tab 2, and no more than 2 tabs will exist.
YouTube and some other high-profile websites block the use of iFrame for security reasons. So if you used an iFrame, it would just load blank.
To open a link to a new tab you would use:
Open me!
I'm not entirely sure that you can control which tab to then replace with further content.
My suggestion would be to do this:
1) Create links to pages with videos embedded in them, with target="_blank".
2) When a user clicks the link, capture it with Javascript (perhaps jQuery) and open the contents of that within some kind of modal overlay like Shadowbox ( http://www.shadowbox-js.com/ ).
This way, the user stays within the same window, without the need for iFrames or new tabs at all. If the user has JS disabled, they'll then get a default "new tab" behavior.
Good luck.
I don't think you control that what you want very easily, and if you can find a hook for this, it most likely is not cross-browser. I'm open to a better suggestion but I think you could use javascript window.open(URL, windowName[, windowFeatures]) and use the same name every time you call it. Then it will replace the previous window. It just will not open in another tab but in a popup.
You cannot control a webpage in another tab and neither can you limit the no. of tabs a browser can open for obvious reasons of security. Limiting the no. of tabs that can be opened or controlling without user's intervention would definitely be considered hacking, bowsers don't allow that.

How to open a window in background onclick? Any problem with this code?

I have a download site (I host some files for free download) where I want to advertise one of my web projects.
The user clicks a link and must reach the target url (the download page).
If possible a second window/tab (advertisement) should open, but in the background.
The second window also should have all the browsers features like navigation bar, bookmark button etc.
It ist not vital that the ad window opensbut it is vital that the the user reaches the download page.
I currently have this code:
<a href="new-location.htm"
target=_blank
onclick="window.location='http://advertise-me.com';">Link mit Fenster</a>
The idea is that new-location.htm is always opend (even if javascript is turned off), and also in a new window so that it is in the foreground. if possible (onclick) the "old" window is redirected to the project that i want to advertise.
No my worries is that the onclick event and the redirect could "steal" the current window and cause the actual link not to be opened in some browser. Is that possible or is the code I use safe?
Popup blocking behavior is not part of the W3C standard. In practice I think what you've done is safe. If the script doesn't run for any reason I doubt it would affect the href direct. I tried out your snippet in a few browsers and they all exhibit the desired behavior you describe.

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