Set up Disqus Multiple Canonical URL in Magento - javascript

I'm trying to integrate Disqus on my test Magento website. I'm using NeoTheme Blog Extension however I disabled the built in comment section and change it to disqus.
The problem was the canonical url. I have a main category http://?????.com/news-and-media/ that has a sub category /blog and /news and others. The blog page can be access as http://????/.com/news-and-media/blog-content and http://????/.com/news-and-media/blog/blog-content, both display the same content. I tried to comment on each url however the comment is missing from the other page and vice versa.
This is my progress so far.
My phtml
<div id="disqus_thread"></div>
<script>
var disqus_config = function () {
this.page.url = 'http://?????.com/news-and-media/';
this.page.identifier = 'blog';
};
(function() { // DON'T EDIT BELOW THIS LINE
var d = document, s = d.createElement('script');
s.src = 'https://????-com.disqus.com/embed.js';
s.setAttribute('data-timestamp', +new Date());
(d.head || d.body).appendChild(s);
})();
</script>
<noscript>Please enable JavaScript to view the comments powered by Disqus.</noscript>
My local.xml
<neotheme_blog_post_index>
<reference name="disquscomment">
<block type="core/template" name="dcomment" template="disqus-comments.phtml" />
</reference>
</neotheme_blog_post_index>
Do you have solution for this canonical? I can't seemed to undesrtand the documentation and example.
https://help.disqus.com/customer/portal/articles/472098-javascript-configuration-variables
How to make Disqus to work with url routing?

You have to fetch the rel canonical value using javascript and use it as your page identifier. I'm not sure if this works.
var canonical = "";
var links = document.getElementsByTagName("link");
for (var i = 0; i < links.length; i ++) {
if (links[i].getAttribute("rel") === "canonical") {
canonical = links[i].getAttribute("href")
}
}
var disqus_config = function () {
this.page.url = '';
this.page.identifier = canonical;
};
(function() { // DON'T EDIT BELOW THIS LINE
Check this link for reference. http://javascript.qahowto.com/Obtaining-canonical-url-using-JavaScript-javascript-url-5b420a

Related

Amazon Search Ads not showing in rails App

Issue
Amazon Search Ads are not showing up in my rails app. It's like the javascript script is not running.
Code
<script type="text/javascript">
amzn_assoc_placement = "adunit0";
amzn_assoc_search_bar = "true";
amzn_assoc_tracking_id = "livingrecipe-show-recommendation-20";
amzn_assoc_search_bar_position = "bottom";
amzn_assoc_ad_mode = "search";
amzn_assoc_ad_type = "smart";
amzn_assoc_marketplace = "amazon";
amzn_assoc_region = "US";
amzn_assoc_title = "Shop Required Equipment";
amzn_assoc_default_search_phrase = '<%= escape_javascript(equipment) %>';
amzn_assoc_default_category = "All";
amzn_assoc_linkid = "78aa42b54ebf16f31c5239f132e3d7a0";
amzn_assoc_rows = "1";
</script>
<script src="//z-na.amazon-adsystem.com/widgets/onejs?MarketPlace=US"></script>
When the webpage renders that code is there and it creates a but there is nothing inside it. Here is a screenshot of what it looks like when I inspect it. Also there are no errors on the page when it loads.
EDIT: I am using Turbolinks and think it might be an issue with that
As per this Forum discussion, Search Ads does not work, use Custom Ads instead.
See! you will see 3 options, click on "Custom ads" and get your js script.

Prevent PDF from auto-downloading and have it Auto Print instead

I have a situation where when a user is viewing their order history, they are provided a link to print a PDF version of their invoice. Currently when the user clicks on the link the PDF will automatically download to their computer.
The 'higher-ups' are wanting that to be changed, so when the user clicks the link to print the pdf, a print dialogue box will appear instead of automatically downloading the PDF.
I've been able to get the pdf open in a new window but when ever the pdf is being called it won't display the pdf but will automatically download it instead.
I've searched all over the internet and SO for a solution but have yet to yield any results. This needs to be done, if possible, via JavaScript or jQuery.
HTML
<p><a id="print_pdf" target="_blank">Click to Print Invoice</a>
JavaScript / jQuery
var print_pdf_link = $('#print_pdf').attr('href');
var linkNo2 = "privatefile.dhtml~useridtext~&file=~username~_rep.pdf";
$('#print_pdf').click(function(){
w = window.open(linkNo2);
w.print();
});
I've also used:
<a href="#" onclick="window.open('privatefile.dhtml~useridtext~&file=~username~_rep.pdf', '_blank', 'fullscreen=yes'); return fal
se;">MyPDF</a>
* please note the text between tilde are placeholders that contain values from the back-end
Thanks for your help!
Try it i hope i would make use of.
var pfHeaderImgUrl = '';
var pfHeaderTagline = '';
var pfdisableClickToDel = 0;
var pfHideImages = 0;
var pfImageDisplayStyle = 'right';
var pfDisablePDF = 0;
var pfDisableEmail = 0;
var pfDisablePrint = 0;
var pfCustomCSS = '';
var pfBtVersion = '1';
(function() {
var js, pf;
pf = document.createElement('script');
pf.type = 'text/javascript';
if ('https:' === document.location.protocol) {
js = 'http://domain.com//main.js'
} else {
js = 'http://domain.com/printfriendly.js'
}
pf.src = js;
document.getElementsByTagName('head')[0].appendChild(pf)
})();
<a href=""
style="color:#6D9F00;text-decoration:none;"
class="printfriendly"
onclick="window.print();return false;"
title="Print">Print</a>

My JavaScript works as inline code but not as an include file. Any ideas why and how to fix it?

I have this form:
<form id="searchForm" class="search_field" method="get" action="">
...
...
</form>
Then this javascript:
var form = document.getElementById("searchForm");
form.doSearch1.onclick = searchPage;
form.doSearch2.onclick = searchPage;
form.showFeatureChoices.onclick = function( )
{
var cbs = form.featType;
for ( var c = 0; c < cbs.length; ++c )
{
cbs[c].checked = false;
}
document.getElementById("featuresDiv").style.display = "block";
}
function searchPage()
{
var form = document.getElementById("searchForm");
var searchText = form.searchBox.value.replace(/-/g,"");
form.searchBox.value = searchText;
if (searchText != "")
{
// collect features to search for:
var features = [ ];
var featTypes = form.featType;
for ( var f = 0; f < featTypes.length; ++f )
{
if ( featTypes[f].checked ) features.push( featTypes[f].value );
}
featureList = "'" + features.join("','") + "'";
searchMsg("Searching for '" + searchText + "' ...");
// startStatusUpdate(1000);
// findTask.execute(findParams, showResults);
var accord = dijit.byId("accordianContainer");
var resultsPane = dijit.byId("resultsPane");
accord.selectChild(resultsPane,true);
doSearch( searchText, featureList );
}
else
{
searchMsg("No search criteria entered, enter search text");
}
}
If I embed this code in same file as the <form..., it works fine.
If however, I have this js in another file and use as include file:
<script type="text/javascript" src="Views/JS/main.js"></script>
I get following error: "Object required" and it points to these lines:
form.doSearch1.onclick = searchPage;
form.doSearch2.onclick = searchPage;
Any ideas how to fix this?
Just a bit more info, the js code shown above in a file called main.js which is in a folder called JS and Js is in a folder called Views. The
Thanks a lot in advance
When you include the JavaScript code in the same page, where is it in relation to the form element? (Before or after it?) How about when you reference the external JavaScript file?
I'm guessing that in the former case the code is at the end of the file, while in the latter case the script reference tag is at the beginning?
If that's true then what's happening is this code is being executed before the DOM is ready:
var form = document.getElementById("searchForm");
form.doSearch1.onclick = searchPage;
form.doSearch2.onclick = searchPage;
If the form tag hasn't been rendered to the DOM yet then that first line won't find anything, and the subsequent lines will fail as a result. One approach is to put the script reference tags at the end, but that seems like a hack to me. Sometimes there are good reasons to keep them in the page header, not the least of which is cleaner management of the code in many cases. There are other ways to hold off on executing JavaScript code until the DOM is ready.

Advert delivery via Javascript document.write

I'm building an advert delivery method and am try to do it through an external Javascript/jQuery page.
I have this so far, but I have some issues with it
$.get('http://url.com/ad.php', {
f_id: _f_id,
f_height: _f_height,
veloxads_width: _f_width
}, function (result) {
var parts = result.split(",");
var path = parts[0],
url = parts[1];
document.write('<img src="' + path + '">');
I can see the page load, but then after the code above is loaded, it creates a new page with just the advert on it. Is there anyway I can write it onto the page where the code was put?
And this is the script web masters put on their websites to include the adverts:
<script type="text/javascript">
var _f_id = "VA-SQ2TDEXO78N0";
var _f_width = 728;
var _f_height = 90;
</script>
<script type="text/javascript" src="http://website.com/cdn/addelivery.js"></script>
Cheers
is ad.php on the same domain as your script? if it's not have a look at this article
here is a code you could use in your html page, where you want the ad to be inserted:
$.get('http://url.com/ad.php',
{ f_id : _f_id, f_height : _f_height, veloxads_width : _f_width }
).success(function(result) {
var parts = result.split(",");
var path = parts[0], url = parts[1];
$('body').prepend('<div id="ad_id"><img src="'+path+'"></div>');
});
the selector (body here) can be an id, a class, ... (see documentation). You can also use prepend() or html() instead of append, to insert the code where you want ;)

Query String for pre-filling html form field

I manage a website for an organization that has separate chapter sites. There is a membership signup form that is on the main website that each chapter links to. On the form there is a dropdown box that allows a person to choose the chapter they want to join. What I would like to do is have each chapter website use a specific link to the form that will preselect their chapter from the dropdown box.
After searching the web, I found that I will probably need to use a Javascript function to utilize a Query String. With all my searching, I still can't figure out the exact code to use. The page is a basic HTML page...no php and it is hosted on a linux server.
Any help would be greatly appreciated.
If you format your url like this:
www.myorg.com?chapter=1
You could add this script to your html head:
function getparam(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.href);
if (results == null)
return "";
else
return results[1];
}
function loadform()
{
var list = document.getElementById("mychapterdropdown");
var chapter = getparam("chapter");
if (chapter>=0 && chapter < list.options.length)
{
list.selectedIndex = chapter;
}
}
The in your html body tag:
<body onload="loadform();" >
Could probably add more validation checks but that's the general idea.
It sounds like what you are looking for are GET or POST requests. For instance, if your user selects "Chapter A" from your form and hits select, you can allow redirects from another site (for instance http://www.yoursite.com/form.html?chapter=A) to allow Chapter A to be preselected. In Javascript this is done by
var chapter="";
var queryString = location.search.substring(1);
if ( queryString.length > 0 ) {
var getdata = queryString.split("&");
var keyvalues;
for(var i=0; i < getdata.length; i++){
keyvalues = getdata.split("=");
}
} else {
chapter = "Not Found";
}
document.getElementById( "ChapterID").value = keyvalues['chapter'];
This is untested, so don't hold me to it :).
maybe something using parse_url
$params = parse_url()
$query = $params['query'];
$query_pairs = explode('&',$query);
$key_val = array();
foreach($query_pairs as $key => $val){
$key_val[$key] = $val;
}
http://www.php.net/manual/en/function.parse-url.php
You would probably have to use an dynamic ajax content. Use the following javascript to read the querystring, then load the html file in that div using this javascript.

Categories