Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude the 'javascript:;' from the next url #535

Open
kzhang-dsg opened this issue Aug 14, 2020 · 5 comments
Open

Exclude the 'javascript:;' from the next url #535

kzhang-dsg opened this issue Aug 14, 2020 · 5 comments
Labels

Comments

@kzhang-dsg
Copy link

Description
Some of the pagination libraries put 'javascript:;' in the next URL when reached to the last page. Currently, the library throws an error:

Access to XMLHttpRequest at 'javascript:;?1597427851817' from origin 'https://xxxxxx' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

Can we validate the next URL, if it is not a valid URL, consider it as a last page?

@fieg
Copy link
Member

fieg commented Nov 30, 2020

Some of the pagination libraries

Do you have any examples?

It sounds like something very specific and I'm not sure if I should bloat IAS to support every other lib out there, but if this is a common thing or used by large libs I can consider it.

@kzhang-dsg
Copy link
Author

Hi fieg,

You can check this example out: https://us.brinks.com/insights. See the next button at the bottom of the page when you go to the last page. The href of the next button becomes href="javascript:;" on the last page.

We dont need to do library-specific logic. Just need to do an additional check to make sure the next button URL is valid before requesting it.

I know there is no customer support for the paid customer but I did pay for the license. I think it will help others to have this feature.

@fieg
Copy link
Member

fieg commented Nov 30, 2020

Thank you for your reply!

I see you point and agree, which leads me to a few questions:

  • What is a valid url and what's not? And how can we validate that?
  • Should IAS do this check, or should it allow users to implement this check themselves, in the few cases where this is needed?
  • Should IAS perhaps execute javascript prefixed hrefs? Not sure if this is even possible tho.

If you have thoughts on these questions, please share.

@kzhang-dsg
Copy link
Author

We can check if the URL is a valid URL by using regex: https://stackoverflow.com/questions/1303872/trying-to-validate-url-using-javascript, or simply check if the URL starts with https?://

To get the absolute URL, we can use this: https://stackoverflow.com/questions/3943281/resolving-relative-urls-in-javascript

It turns out that the .href attribute of a A element (not .getAttribute('href'), but .href) returns the resolved (absolute) URL.
  1. For <a href="https://example.com/page1">, the .href will return https://example.com/page1;
  2. For <a href="/page1">, the .href will return https://example.com/page1;
  3. For <a href="javascript:;">, the .href will return javascript:;;
  4. For <a href="javascript:alert('111');">, the .href will return javascript:alert('111');;

Once we got the absolute URL, we can check if the URL is valid or not.

@fieg
Copy link
Member

fieg commented Dec 7, 2020

Thank you for your detailed reply 🙏 I will take it into consideration. If you are up for it, feel free to send in a PR with a code proposal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants