How do I use sessions to display a popup after Nth page? - javascript

I have a popup from Survey Monkey but it pops up straight away. That's not really any use for anyone as research about a user's experience of a website relies on the user having used the website for at least a few minutes.
I want to run this code only on the Nth (let's say 7th) page on that session to the site. So only after a user has delved deeper into a site will they be requested to fill out a survey.
I'm a novice but I know that javascript resets on every pageload/refresh so that on its own seems to be out for using setTimeout.
I was thinking if I could somehow track number of pages using a session then only load the javascript when number of pages viewed = x then it would solve the problems but not really sure where to start?
Any ideas would be greatly appreciated, the script for the popup is below:
(function(t,e,n,s){var c,o,l;t.SMCX=t.SMCX||[],e.getElementById(s)||(c=e.getElementsByTagName(n),o=c[c.length-1],l=e.createElement(n),l.type="text/javascript",l.async=!0,l.id=s,l.src=["https:"===location.protocol?"https://":"http://","widget.surveymonkey.com/collect/website/js/surveyidnumbergoeshere.js"].join(""),o.parentNode.insertBefore(l,o))})(window,document,"script","smcx-sdk");

Put this code in head of your site:
session_start();
if(!isset($_SESSION['survey_counter'])
$_SESSION['survey_counter']=1;
$showSurvey=false;
if($_SESSION['survey_counter']++ >= 7)
{
$showSurvey=true;
$_SESSION['survey_counter']=0;
}
and this code where you want to echo JS:
if($showSurvey) echo 'YOUR_JAVSCRIPT_CODE';

Related

Using node to bring in a javascript page

I made a website that has about 400 lines of javascript code, on the front end. I want to put it on the back end so that when people visit the web page that uses the javascript, and click the submit button, only then does the website go to the server and use the necessary JS code, however with all the tutorials ive read and watched i cannot find anything specific to this, can anyone please help? thanks in advance

How to use jquery (or JS) to check if a conditionally included file has been loaded

I apologize in advance that this is such a basic question (I'm a newbie), but I haven't been able to find the answer.
I'm working on a WordPress membership site that presents a full post when the visitor is a member, but when a non-member tries to view the page, a file loads ("notMember.php") that basically says "Hey, you're not a member".
I've been asked to track how many times this notMember.php is being shown on the site.
We're using Google Analytics and I want to record each load of the notMember.php as an event.
I understand how to track events in Google Analytics, but what I can't come up with is the code that basically amounts to finding out whether or not notMember.php has been loaded.
I basically want a script that says:
If (notMember.php has been loaded) {
// run GA event tracking code
}
But I don't know how to come up with that conditional.
Can anyone help? Thanks.
Put the GA tracking code in a <script> element and then put that inside notMember.php.

determine final destination/url returned by a asp(?) by script

So, I'm sure this will get down voted and I'll be banned from the site because I'm a total newb that asks elementary questions/wrong questions/vague questions that irritate the community. But...I'm not sure where else to turn, this seems to be one of the best communities.
I use a live chat service. And they have this cut/paste bit of markup that you drop into your page and it'll display a jpeg indicating whether or not the chat service is open.
https://rci.ehosts.net/netagent/client/invites/chatimage.aspx?style=style0&questid=44D115D4-5242-476F-AE56-6AEECE8E9343&portid=28586436-7974-4E4B-BBDE-73E63BC3EAED&imagelanguage=en-us&customopenimage=https%3A//rci.ehosts.net/netagent/custfiles/en_chat_open.gif&customcloseimage=https%3A//rci.ehosts.net/netagent/custfiles/en_chat_closed.gif
If you drop that into a browser, it doesn't seem like anything happens. But if you set that as the src attribute of a image tag in a html page, it displays the appropriate image (chat online/chat unavailable).
My question is...can I determine the outcome of that script without dropping it into the page? Via either javascript or php? What'd like to do is make a script of my own that will determine which image is returned and do things other than just displaying the chat online/chat unavailable images.
Thanks!
EDIT: oh, the above url will redirect to the correct image if you change all the & to just &
I ended up following the redirect to see which image it takes me to. It was the only way I could think of. Ended up basically copying example #2, except that I returned the headers location, from the following link:
php manual

Javascript: Redirecting to another site through a popup

I'm quite bad with Javascript and I can't work out a solution I need help to. I'm having a website and I'm trying to make a redirection to another site, but through a popup.
Example :
<script>alert(This will prompt up the message)</scrip>
<script>window.location="http://This-will-redirect-me-to-another-link.com";</scrip>
Like you can see I could simply use the second javascript to redirect the persons to another page, but due some reasons I can't use it as it will work only for half of the page(the script would be kinda 'sandboxed'), but if I'd make a popup(the first alert script) the second script would get out of the 'sandbox'. Is there anyone who has any ideas how I should implement this or can it be done otherwise with PHP or HTML?
I'm having a MyBB forum and there's a shoutbox for it which I'm using. There's a command which will change the notice of the shoutbox and the command is as such /notice New notice | But I noted that the new notice can be changed with javascript and it'll work such as /notice js code here | Then I thought that what if I would make such a javascript that would redirect people to another webpage. As I'm having such a forum where it's needed to redirect from the main page to another one, I'd like to apply it. Then Staffs could do it in the forum very well, but there's a problem. by adding
/notice window.location="http://This-will-redirect-me-to-another-link.com";
It'll affect only the shoutbox and shoutbox is being redirected to another webpage, but as an alert works for the whole forum I thought maybe I can redirect them to somewhere else with the alert. I want to know is it possible with just one script then Staffs would be able to do it. I know it's a serious security risk & it can be otherwise also, but I'd really like to experiment with it.
I hope someone can help. :)
Try:
window.open('url to other site', 'window name', 'width=900,height=650,scrollbars=yes');
If I understand you (if not please correct me), you can put a tag on popup or another place:
<a href="http://another.site.com/"
onclick="return confirm('Do you want to see another page?');">Redirect</a>

Javascript Slider using Wordpress Loop

I am having issues with a slider I have on a wordpress site. www.towntalkradio.com
1) The back button is not functioning
2) The code is supposed to call a count of all of the posts in the specified category and display all of those posts. The count is not working correctly and only part of the posts are being displayed (ex. 7 when there are 19 in the category)
I inherited this code and I have very limited experience with this setup. Any suggestions would be greatly appreciated. I apologize if I did not submit this correctly, I am new here.
Javascript
Index.php
The value you are getting is the posts per page setting.
(Settings > Reading > Blog pages show at most)
give this a go on line 9:
<?php query_posts('cat=4&order=DESC&posts_per_page=-1');?>
be sure to use wp_reset_query() after your loop.
query_posts is meant for altering the main loop, WP_Query or get_post
might be better options when running multiple loops.
http://codex.wordpress.org/Function_Reference/query_posts
http://codex.wordpress.org/Class_Reference/WP_Query

Categories