Disable open new tab and new window when page loaded using javascript - javascript

I want to ask about how to disable open new tab or open new window in browser when page loaded using javascript or jQuery, or may be there is a plugin should i used. It will used on exam page that the student forbid to browse google or some search engines for finding exam answer. Please give me some suggestions.
Thank you

There is no way to prevent opening new tabs of the browser from the browser's page, but it is possible to implement using browser's add-on. You can check tabs API (Firefox, Chrome) for browser's add-on, it contains all necessary methods and events to allow you to control browser's tabs.
You can implement such add-on for both Firefox and Chrome.

On what action is your new tab opening? Provide information on that.
If you are using an anchor <a> element,
use target="" to change the target of the new page. link
Use an <iframe> to load external links on your page.
Visit the Mozilla's TABS API.

Related

How to open a browser app which is listed in chrome://apps

Chromium-based browser has the apps page at chrome://apps
There are some apps that I have installed into it. Is it able to launch one of them from JavaScript somewhat just like opening file selecting box?
I can open chrome://apps by setting this URL in to a link, but how about a single app?
Copied from: Open Chrome in a new window (Chrome app)
Sadly, there's no way to do that I know of.
Using window.open in an app's context is a bit of a hack, but results in the URL being open in the user's default browser (not necessarily Chrome). There's no control as to how the browser chooses to open it.
There's a Chrome App-specific API that was created specifically with "open a page in Chrome" in mind, chrome.browser. However, it still doesn't provide an option to open in a new window.
The closest you can get is to create your own "browser": an app window with an in it. Then you have full control over the presentation, but it's not integrated with Chrome's profile and may require additional work to implement things like dialogs and browser controls. See the Browser sample app and documentation.
You may need the app id which you can then append to the URL. I am not entirely sure how you would find but if you go to the apps page on chrome, drag the icon of the app to the search bar in the browser, you should get the full link.
For instance, I dragged the Google Slides Icon onto the search bar and it gave me this url chrome-extension://aapocclcgogkmnckokdopfmhonfmgoek/main.html. So, you may give it a shot! Try to open the chrome apps page, then drag the app you want to open in new tab onto the search bar.
Hence, using Javascript:
window.open("chrome-extension://aapocclcgogkmnckokdopfmhonfmgoek/main.html", "_blank");
Opens Google Slides App in a new tab.

URLs of currently open tabs of a browser in JavaScript [duplicate]

I am using Mozilla Firefox and I am trying to figure out a way to access the content of other tabs in the same window using JavaScript and the DOM (I am open to other techniques if exist).
E.g., I want to run JavaScript code in tab1 which can find the title of some other tab. Basically I need this so that I can identify a tab which has opened due an href in my current page without using window.open method. All I want is a simple hyperlink which opens a page belonging to the same domain as the current page (the page should be opened in a new tab). Now I want to be able to access this new tab from the current tab.
Whilst you can easily open a new window using JavaScript, I'm sure that is as far as it goes. From a security point of view you wouldn't want JavaScript in one tab being able to query / access the DOM in another tab. Any site would then be able to gain access to your bank account details, etc. if both sites were opened in separate tabs.
You can access the new window/tab if it was opened with JavaScript and the page indeed is in the same domain.
You can open the window/tab like so
var win = window.open("/path_to_page");
Then you'll have to wait for the page to load before you can access e.g. the title.
win.onload = function(){ alert(win.document.title); };
You could use HTML5 cross-window messaging (archive.org link...but that's kind of cutting edge.
Even in that case, you'd probably need to hijack the <a> tag 'click' event with JavaScript and open the window yourself so that you'd have access to the new window object for posting messages.
Try setting a cookie which is accessible to any page in the same domain. On other pages, use a JavaScript timer to check if the cookie value has changed and when it has you can use its value and take an action.
It worked for me.
Well, this would not be possible, you could try
<a target="_blank" rel="opener" href="about:blank"></a>
This makes a link that opens an about:blank, this will have the same domain as the page that opened It because of the Same-Origen-policy.

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.

Google Chrome Extension

How do I open a link in a new tab in the extension HTML.
E.g.
clicks on icon
sees Google chrome window which has the window.html
inside there are two links, one link to open a link in a new tab, other in the original tab.
I used window.location, doesn't work like that.
If the page is indeed in a google chrome extension, you can force the browser to open the page in a new tab using javascript (which you know is enabled sine you are a google chrome extension).
chrome.tabs.create({url:"http://somewhere", selected:true});
Your extension will need the tabs permission.
See: http://code.google.com/chrome/extensions/tabs.html
I don't know why this question has two upvotes, but anyway you can try using the target attribute for anchor elements.
<a target="_blank" src="http://myFancyUrl">This is a link to a new tab</a>
However, it won't open in a new tab unless the user has the navigator configured that way (usually does).

Categories