I am trying to display a Disqus commenting embed on a website, but I only want it to display the embed if it's before 2nd February 2014 UK time.
EDIT: For clarity, It should always display the embed before the 2nd Feb 2014 on any date but never after.
The PHP code I have is:
<?php if (time() <= strtotime('2014-02-02 00:00:00')) { ?>
<div id="disqus_thread"></div>
<script type="text/javascript">
var disqus_shortname = 'mysite'; // required: replace example with your forum shortname
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<noscript>Please enable JavaScript to view the comments powered by Disqus.</noscript>
comments powered by <span class="logo-disqus">Disqus</span>
<?php } else {
//do something else
}?>
However, it doesn't seem to be displaying on posts. I have replaced 'my site'. This is just for an example.
Related
I am using below PHP code for Displaying AdSense Ads only for search engine visitor.
But now I need HTML/JavaScript Code for Displaying Ads on search engine visitor.
I'm trying to create HTML/JavaScript code, but failed.
Can I modify/create this HTML/JavaScript code?
Have any solution? or Have any HTML/JavaScript code?
<?php
$referrer = $_SERVER['HTTP_REFERER'];
$my_domain = "example.com";
$search_engines = "google|yahoo|bing|altavista|digg";
$pattern = "((http(s)?://)(\w+?\.)?(?!{$my_domain})({$search_engines}))";
if (preg_match("/{$search_engines}/i", $referrer) != false) {
echo <<<END
<script type="text/javascript"><!--
google_ad_client = "xx-xx-xxxxxxxxxxxxxxxxxx";
/* xxxxxxxx xxxxxx xxx xxx xxx xx xxxxxx */
google_ad_slot = "xxxxxxxxxxxxxx";
google_ad_width = xxx;
google_ad_height = xxx;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
END;
} else {
// Show something to visitors not referred by a search engine
}
?>
Please help me, Sir.
It's a little bit stupid, but you definetely can translate it to js:
<script type="text/javascript">
if (document.referrer.match(/google|yahoo|bing|altavista|digg/)) {
google_ad_client = "xx-xx-xxxxxxxxxxxxxxxxxx";
/* xxxxxxxx xxxxxx xxx xxx xxx xx xxxxxx */
google_ad_slot = "xxxxxxxxxxxxxx";
google_ad_width = xxx;
google_ad_height = xxx;
var script = document.createElement("script");
script.setAttribute("src", src);
document.getElementsByTagName("head")[0].appendChild(script);
} else {
// Show something to visitors not referred by a search engine
}
</script>
I'm adding disqus to my website and I was wondering if there's a way to use the page's url to fill in the variable for disqus_url
I know that window.location.href will find the url, I just don't know how to use that inside of a function.
This is what I've tried:
<script type="text/javascript">
(function() {
var disqus_url = window.location.href;
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
Yes, you can. However, window.location.href is the default, so you really don't need to provide it.
Note that this will most likely treat http://example.com/helloworld.html and http://example.com/helloworld.html?123 as two different threads.
See https://help.disqus.com/customer/portal/articles/472098-javascript-configuration-variables#disqus_url
I have an ad that will appear when certain conditions, and when that ad appears, the ad will detect the width of the screen and use the ad size that I specify.
I did this using JavaScript, and inside JavaScript and all are in PHP. Problems arise when writing in document.write.
Could you please help me solve this problem.
This is my code:
<?php
if(!empty($variable1)) {
echo '
<script type="text/javascript">
var swidth = screen.width;
if (swidth >= 1218) {
document.write('
<script type="text/javascript">
document.write("
<script type='text/javascript'>
var adcode = {abcdefg};
</script>
<script type='text/javascript' src='http://domainname.com/ads.js'></script>
");
</script>
');
}
</script>
';
} else {
if(!empty($variable2)) {
echo $ads2;
} else {}
}
?>
from line 13 to 22 replace:
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'http://domainname.com/ads.js';
$("body").append(script);
var script2 = document.createElement('script');
script2.type = 'text/javascript';
script2.src = 'sc.js';// or url to the script file;
$("body").append(script2);
and sc.js:
var adcode = {abcdefg};
BUT
The best way to add JS in PHP:
<?php
// ...
?>
<script src="url_to_script"></script>
<?php
// ...
?>
Manipulations with DOM elements must be defined in JS and not affect PHP.
I'm using a plugin that I found from searching the web called Apprise. It has worked well for what I have needed thus far. But, I want to apprise the facebook login plugin and to to that I need to following code:
<fb:login-button scope='email,publish_stream'>
Login
</fb:login-button>
<script type='text/javascript' src='http://connect.facebook.net/en_US/all.js'></script>
<script>
window.fbAsyncInit = function() {
FB.init({
appId: '123456789',
cookie: true,
xfbml: true,
oauth: true
});
FB.Event.subscribe('auth.login', function(response) {
window.location = '/fb_redirect.php';
});
FB.Event.subscribe('auth.logout', function(response) {
window.location.reload();
});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
Anything that you want to be apprised can be done by putting
apprise();
in the javascript. However, putting the <script></script> tags inside of the JS code (apprise();) causes all sorts of confusion because it's not clear where the JS code ends.
Any ideas?
The method that works in both <script> blocks and inline Javascript is \uxxxx, where xxxx is the hexadecimal character code.
< - \u003c
> - \u003e
" - \u0022
' - \u0027
\ - \u005c
& - \u0026
Demo:
HTML:
<div onClick="alert('Hello \u0022>')">click me</div>
<script>
var s = 'Hello \u003c/script\u003e';
</script>
You need to break up the close script tag, if I'm reading your question right:
var test = '...... </scr'+'ipt>......';
Script tag in JavaScript string
Try breaking up the tags:
apprise('<scri' + 'pt>alert("hello");</sc' + 'ript>');
You need just to escape the / character:
BAD, exception
<script>
var html = "<script></script>";
</script>
GOOD
<script>
var html = "<script><\/script>";
</script>
This code displays the comments when the thread disqus_identifier is pointing to returns comments, but when it's a thread with zero comments, I get an error message that reads "We were unable to load Disqus. If you are a moderator please see our troubleshooting guide."
<div id="disqus_thread"></div>
<script type="text/javascript">
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
var disqus_shortname = 'my_short_name'; // required: replace example with your forum shortname
var disqus_identifier = 'random';
/* * * DON'T EDIT BELOW THIS LINE * * */
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
There has to be some way to create an empty thread. Thanks in advance.
Look like your site is inaccessible, you can use Disqus JavaScript configuration variables
var disqus_developer = 1; // developer mode is on
This tells the Disqus service that you are testing the system on an inaccessible website, e.g. secured staging server or a local environment
http://help.disqus.com/customer/portal/articles/472098-javascript-configuration-variables
Also verify your disqus_shortname variable