question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

HTML URL Variable Substitutions not working when user opens link in new window

See original GitHub issue

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

  1. Click on the link normally to observe the variable substitution working correctly
  2. 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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
jpettittcommented, Apr 23, 2018

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.

0reactions
staceyfentoncommented, May 21, 2018

That’s great @alabiaga, thanks for letting me know!

Read more comments on GitHub >

github_iconTop Results From Across the Web

URL Link Substitution using Variables
Assume we have a variable called my_url, which is the URL of a web page or document file. The examples below are the...
Read more >
Open a URL in a new tab (and not a new window)
This is a trick, function openInNewTab(url) { window.open(url, '_blank').focus(); } // Or just window.open(url, '_blank').focus();.
Read more >
<input type="url"> - HTML: HyperText Markup Language | MDN
A single properly-formed absolute URL. This doesn't necessarily mean the URL address exists, but it is at least formatted correctly. In simple ...
Read more >
URL Canonicalization and the Canonical Tag
A canonical URL is the URL of the page that Google thinks is most representative from a set of duplicate pages on your...
Read more >
Query string - Wikipedia
A query string is a part of a uniform resource locator (URL) that assigns values to specified parameters. A query string commonly includes...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found