Comments (13)
@u12206050 Yup, it uses window.open()
to open the dialog, let me investigate this further for you
from ngx-sharebuttons.
The main problem is the use of window.location.href, I believe angular does have a Location object that you can use. Luckily window.open() doesn't get called when rendering on the server so that isn't such a big deal.
For others wanting to fix this, I did the following to fix the window.location.href:
Replaced window.location.href
with
typeof window != 'undefined' ? window.location.href : typeof global != 'undefined' ? global.url : ''
And then in server.ts where Universal is being called to render do the following:
/* Declare both global and the url property for typescript concerns */
interface Global {
url: string;
}
declare var global: Global;
/* In the function that responds with the rendered html */
let ngApp = (req, res) => {
let url = req.originalUrl || '/';
global.url = url;
...
}
from ngx-sharebuttons.
@u12206050 I got it, it turned out that there's no window
in node, @ViewChild('firstModal')
could be a solution
from ngx-sharebuttons.
Is this fixed now?
from ngx-sharebuttons.
@u12206050 I haven't played with Universal yet, but now sharebuttons will only use window.location.href
if the [url]
input is not provided, so pass your current url to the input and it should work
from ngx-sharebuttons.
@u12206050 For opening share window which uses window.open
I'm not sure if it can be fixed in Universal, I talked about it in angular group
I would have used a modal instead of window,open
, but fb have SAMEORIGIN
policy, which disallows sharing within iframe outside of their domain..
from ngx-sharebuttons.
Could you just please do the following, it fixes compiling on universal side at least.
Replaced window.location.href
with
typeof window != 'undefined' ? window.location.href : typeof global != 'undefined' ? global.url : ''
from ngx-sharebuttons.
@u12206050 okay it's merged now, please download the source manually and test it in your app, if it works I will push it to npm, because I'm not sure if it would work with window.open
. isn't it a problem for universal to compile?
btw, I tried to replace window.location.href
with router.url
, location.path()
and location.prepareExternalUrl(location.path())
, they all don't return the full path, also couldn't find any alternative to window.open
. we can't get rid of it
from ngx-sharebuttons.
Ok, the changes should work, except that window and global are undefined in the context of typescript when compiling. I made a merge request with the interfaces for them.
from ngx-sharebuttons.
I tried to use it on a fresh Universal Starter installation, I imported ShareButtonsModule
in both app.browser.module
and app.node.module
, it worked.
The only issue I found is when I click on Pinterest button. Cannot read property 'getAttribute' of null
, but everything else is working as expected!
BTW this is without the changes we made earlier 👆
from ngx-sharebuttons.
Changes are merged and pushed to npm in 1.0.7
from ngx-sharebuttons.
Did you make use of the share buttons on universal side or do you only render them client side?
from ngx-sharebuttons.
Did you make use of the share buttons on universal side
@u12206050 I just used it the same way I would use it in a normal angular app and it worked, I'm not sure what you mean by make use of them on universal side because I'm not technically familiar with universal yet. I have been told that global variables like window
are not available in node apps, and we can't get rid of window
completely since there is no other way to open the sharing dialog in a new window (not new tab).
from ngx-sharebuttons.
Related Issues (20)
- SMS button opens Messages on Mac but without the URL HOT 3
- Instagram & Share launch Button HOT 2
- Discord button HOT 1
- skype button
- instagram button
- gmail button is not available HOT 1
- When click on Messenger and Viber nothing happens, link doesn't open HOT 1
- setting meta tags doesn't seem to matter? HOT 4
- Share via Mastodon HOT 1
- how to add role to given tag HOT 2
- Opened output not firing HOT 3
- Whatsapp redirection to 'api/web .whatsapp.com' controlled manually HOT 1
- :bug: v12.0.0 says tumblr and reddit are no longer available to use with shareButton directive
- can we open shared details in pop up instead of new tab ? HOT 2
- i am geting error with Angualr version 15 HOT 6
- How to use share buttons vertically? HOT 1
- share-buttons inputs don't work within square brackets. HOT 1
- add or replace twitter option for X HOT 5
- Unable to share image HOT 1
- Can't install; error with cdk version HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ngx-sharebuttons.