Youssef Subehi
Youssef Subehi

Reputation: 2860

Getting Website URL using JS not working with https

I'm using this JS code to get the page url, title and send them to the server to store them in a database, like a button you bookmarked in your browser toolbar and click it on any website you have open and it will get the website's URL and TITLE.

However this code is working great BUT it's not working with (https) url

javascript:(function(){var jsScript=document.createElement('script');
jsScript.setAttribute('type','text/javascript');
jsScript.setAttribute('src', 'bookmark.php?url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title));
document.getElementsByTagName('head')[0].appendChild(jsScript);
})();

It's working good with all url's Except (https) links like
https://facebook.com
https://google.com

It's not working at all with these kind of links.

Any improvements that could make it work with https links?

Thanks in advance.

Upvotes: 2

Views: 1682

Answers (2)

alok bhade
alok bhade

Reputation: 1

use your all personal js. don't take from any external link js and css. if you have all css and js in your project folder then it will work properly. thank you

Upvotes: 0

Bud Damyanov
Bud Damyanov

Reputation: 31829

You`ll always have problems getting HTTPS URL, unless the server your are sending data is also HTTPS. Your server may need SSL certificate in order to complete the task. However, facebook, google still have http:// access enabled, although this URL is converted automatically to https://, so you might be able to fetch some of those requests.

Edit: This is because so called Cross-Origin Resource Sharing (CORS).

Upvotes: 1

Related Questions