HTML URL Variable Substitutions not working when user opens link in new window
What's the issue?
We are trying to use variable substitution in links as documented here.
Here is an example of the HTML we are using:
<a href="//example.com/?SRC=QUERY_PARAM(SRC,XXXX)" data-amp-replace="QUERY_PARAM">Go to my site</a>
This is working fine if you click on the link normally, but we have noticed that if we right-click on one of these links, or press down on a mobile device to open in a new window, the variable substitution does not work correctly. Instead of linking to //example.com?SRC=XXXX we get //example.com?SRC=QUERY_PARAM(SRC,E132).
How do we reproduce the issue?
Here is a link to the test case - http://jsbin.com/daduzekiho/edit?html,output
- Click on the link normally to observe the variable substitution working correctly
- Go back to the test case and right-click/press and hold on the link and open in a new tab/window. Observe that the variable has not been substituted.
What browsers are affected?
Seems to affect all browsers. We have observed this behaviour in Chrome, Safari, Firefox and Microsoft Edge.
Which AMP version is affected?
Version 1524089272632
/to @choumx
Right click takes a different path in the browser, it doesn't fire the click event handler so we never do the substitution. May be fixable by catching right click events, stashing the original url somewhere and updating the href url in place.
/cc @alabiaga
@jpettitt right. This looks to be an easy fix for the variable substitution case just by just binding the same handler for the 'contextmenu' event as we do with the 'click' event handler which updates the inlined href with the variable substitutions. Then when the user chooses open in new tab or window, the updated href is reflected. But this does not work for the other type of links we support, like A2A links where a right click would just trigger the link immediately which is not what we want. I'll put out a fix to handle the first case and follow up with another ticket to resolve the other click handler situations Thanks!
@alabiaga thanks so much for resolving this issue! Do you know when we will see this fix in production?
@staceyfenton sorry for the delayed response as I was on vacation. If I am reading and understanding the release cycle docs correctly, it should go out to prod tomorrow. Will verify tomorrow as well and ping back if otherwise. Thanks
That's great @alabiaga, thanks for letting me know!