Difference in Chrome between `target="_blank"` and Right Click + `Open Link in New Tab` - html

Suppose I have a link to Google of the form
Google
There are a couple different ways to open this link in a new tab:
Left click on the link
Right click on the link and select Open Link in New Tab
I've noticed on an app I work on that there is different behavior between #1 and #2. For example, when I console out window.opener for #1 I get an object like
wheres #2 gives me undefined.
What are the differences between these two ways to open the link? I can't find any information about how a browser (in my case, Chrome), might handle these cases.

I had the same problem, two different behaviors were happening in those two cases in an application I was working on. I had to search everywhere to see why, only to find your question that helped me identify the problem.
in case #1, of course when you left click the link, the user is giving the developer the choice of whither to open in a new tab. whereas in case #2, the user is making the choice instead.
case #1 is like doing window.open(URL, '_blank');
case #2 is like opening a new tab and manually typing the URL;
the only thing I found is that when you open the URL with target blank (case #1), that new tab or window will link to the parent (opener) by window.opener until you close that window, the opener will be back to null
as far as behavior, the source code of the new URL may include logic on window.opener you may need to search if this was the case. I don't see why the browser would treat them differently, it has to be from the source code.

Related

Why would links in an object or iframe (I've tried both) start opening in a new window

I'm working on an application that has many links. They all open in the same window, until today. All of a sudden, in all browsers I'm testing in, 3 links in an iframe or object (I've tried both) start opening in a new window. I can't seem to stop this.
An object example follows. The dolnks program generates 3 simple links like the one following the object example and these links open in a new window.
<OBJECT ID='fixed' DATA='dolnks.cgi?str=$params' TARGET='dynamic' NORESIZE></OBJECT>
darea.cgi?str=$dogstr
Can someone help me understand this and how to get these links to open in the same window.
All links that now open in the same window or should be opening in the same window are from
the same domain.
I now have to close the link instead of using the back button.
Thanks,
craigt
I imagine it's because of your TARGET attribute, although it's not using one of the special target values:
target
Where to display the linked URL, as the name for a browsing context (a tab, window, or ). The following keywords have special meanings for where to load the URL:
_self: the current browsing context. (Default)
_blank: usually a new tab, but users can configure browsers to open a new window instead.
_parent: the parent browsing context of the current one. If no parent, behaves as _self.
_top: the topmost browsing context (the "highest" context that’s an ancestor of the current one). If no ancestors, behaves as _self.
From the MDN Docs: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attributes
Note though that the docs for object do not list a target attribute, so that behavior is apparently undefined, and probably varies depending on the browser, and the plugin displaying the object.
Check to see if it's the items with a target attribute (case does not matter) that are working "wrong", and see if removing that attribute fixes it. If that's not it, next check to see if there are javascript being loaded. Try turning javascript off (hopefully the relevant links are not generated with javascript) and see if that fixes the behavior. If turning javascript off is too heavy handed, you can use the javascript console to see what listeners are attached to the links.

Can't click on obj or link for payment in pop-up cart

This problem is specification on RobotFramework(Selenium) language.
I would like to Click on button ("i.stack.imgur.com/PTNYl.jpg") after confirm purchasing
For clear information please see below picture with ordered number
Select 2 items.
Click "สั่งซื้อ" (confirm purchasing).
Pop-up of cart will show about description and Payment button image.
(Click)
Website : "www.tarad.com/product/5807261#cart"
Code : (saved to .txt and run on Command Prompt)
Open Browser http://www.tarad.com/product/5807261#cart chrome
Select From List By Value product_qty 2
Click Button f_buy
Wait Until Page Contains Element xpath=//*[#id="flyout_cart"]/div[6]/a/
Click Link xpath=//*[#id='flyout_cart']/div[6]/a/span[#id='btn-payment']
(click)
I can find this pop-up cart description, but can't click on button for payment, moreover, I try using Click Image, Click Link, Click Element with payment button xpath that got from Chrome Browser.
I apologize about my English writing and thank you to your attention.
Don't use the Click Link and Click Image, if you are not sure the underlying element is that type - use the general Click Element. Looking at the locator you've specified, the target is a span, so Element should do.
Regretfully I cannot open the site right now to check the html (mobile...), but as far the locator you are using:
do not use indexed paths - the div[6] up there - if the page structure changes just slightly, they can easily brake (which is probably the case with your run)
try not to use direct descendants (the single /) except if you're not sure the structure will remain the same in the long run - they are much faster than "any descent down" - i.e. //, but again, if the structure changes in a future build, they will break. For good or bad, these two negatives are what browsers generate when you ask them to create an xpath
finally, I see in your sample the target span has an id attribute - that is (almost always) the safest and fastest locator strategy to use. So remove everything before it, and address the element as "id=btn-payment"
E.g. change the last call to
Click Element id=btn-payment
Hope this will resolve it for you

Open a Vaadin `TabSheet` tab into a separate window

I want to give my users the option of opening a tab into its own window rather than merely switching the current window’s display to that tab. I have lots of tabs in my app, and the user often wants to study a few of those over long periods of time. For example, the user may watch charts being updated over time via Push.
Currently I add an "Open Window" button to a tab's layout. This opens a new browser window with the current tab’s layout.
Is there any other way to do this? A context-menu on the tab itself? User holding down a keyboard modifier (Control key, Command key, Option/Alt key) while clicking the tab?
Actually, there is one trick:
tabSheet.setCloseHandler((tabsheet, tabContent) -> {/** make new window **/});
Of course it works if tabSheet is closeable.
So if anybody click close button then you could do your own logic - in this example open new window.
But it could be misleading. To handle this problem you could replace close caption from x to any other more meaningful sign.
For example, look at Valo TabSheet demo. If you look in HTML code, than you notice something like this:
<span class="v-tabsheet-caption-close" aria-hidden="true" aria-disabled="true">×</span>
I think you are able to change this x using for example JavaScript.

Duplicate a tab in Chrome without Reloading the Page?

Is there any way to completely duplicate the state of a current tab in Google Chrome? I want an exact copy of the current state of the page without having to reload the page in another tab.
An example use case:
While browsing a "slideshow" on a news website, I want to preserve the current slide that I'm on, but create a duplicate so that I can continue viewing the next slide. If I simply Right-Click and "Duplicate" the tab, the new page will completely Reload, reprocessing all of the Javascript and running the pre-slideshow advertisement again.
In short "NO" you can't.
I am not expert on this
but a similar behavior can be achieved in some ways i know :
Dump the whole DOM
Never tried this though. You can convert the DOM to a string, pass it to the new window and then parse it as a document. This will let you lose your DOM events and State manipulation javascript. (But that's good for your case)
var dtab = window.open('about:blank', 'duplicate_a_tab');
dtab.document.open();
dtab.document.write("... yout html string ..");
dtab.document.close();
Develop an extension
Let the users continue on the current tab with the current state, your extension should be able to capture the screenshot of that area and open that screenshot in new tab. There are plenty of screenshot taking extensions are available in the market.
If that website is your own
You can develop your services that uses state locally like progressive web apps. Give a link separately to 'duplicate' which will eventually open the same URL in different tab with the same local state and with the flag do-not-sync.
This will not work when the user uses browser inbuilt duplicate
feature.

Opening links in a specific tab - from an email

I have a registration system on my website which uses the common activation email trick.
This email simply contains instructions and a link to the activation page on my website.
So suppose I registered on the site, opened a new tab to check my emails and then clicked on the link, which will open in another new tab, resulting in two tabs open on the site (of which one is btw still telling them to o check their mail).
Is there a way to get the link in the email to open in the first tab on my website? (Or open a new tab if the previous one was closed or moved to another domain).
Thanks for any help/suggestions!
You can name your current window/tab with a JavaScript assignment:
<script type="text/javascript">
this.name = "mainWindow";
</script>
Then you use that name as value for the target attribute in links, like
<a href="nextPage.html" target="mainWindow">...
If mainWindow does not yet (or no more) exist, it will open in a new tab.
Update
The above stuff does not solve the OP's problem, because for links opened from emails, the target attribute will usually not be transferred from MUA to browser (except maybe for webmailers, but we cannot rely on this). So I was thinking of some kind of landing page which uses JavaScript to achieve the desired effect:
If target window/tab `mainWindow` has already been opened, focus it, perform activation there, and close ourselves.
If target window/tab does not exist, perform activation right where we are.
If this worked, you would only see a second open tab for a moment (case 1), before it closes itself. Yet it is not possible to "close ourselves", as I learned here and here - so in the end there would be a superfluous tab left, which should have been avoided. Seems like it cannot be done, sorry!