Page 1 of 1

Not directly related to wwb

Posted: Thu Oct 01, 2020 12:14 pm
by alex4orly
I just need some help....
I have a "pages.html", in it, a JavaScript function.
At the end of that function, I am calling an external "page.php" to update a record on the server.
I am using window.location.href to do the job.

The problem is, this action is moving the visitor from the current page onto the page.php, which has no UI at all.

Is there a way, to do that function, but stay with the calling page?

The best would be to have the PHP script as part of the calling page, but PHP script is server side...

Any suggestions?

Cheers

Re: Not directly related to wwb

Posted: Thu Oct 01, 2020 2:46 pm
by BaconFries
Have you considered using window.open(url, "_self") over window.location.href = "url"; were "url" is the page.php. Note using this it will stay on the same page but open in a "New" window.

Re: Not directly related to wwb

Posted: Thu Oct 01, 2020 8:43 pm
by alex4orly
Yes, I tried that, but it still ends up with the PHP blank page, not the current page it was called from

Thanks again

Re: Not directly related to wwb

Posted: Fri Oct 02, 2020 6:42 am
by alex4orly
Well, here are some details of my setup

1) I have a button, which upon clicking it - it reveals a hidden Modal hidden dialogue
2) In the Events action - I have TWO calls, to two javascript functions:

The first one - WritePageVisit(), is a call to a php script on the server, here are the scripts

The calling function has in it the following script
function WritePageVisit()
{
var MyVariable = getCookie('beleura21');
alert(MyVariable); - this pops up - indicating the script is called
var VariablePlaceholder = "myvilla=";
var MyPage = "&mypage=";
var PageName = location.href.split("/").slice(-1);
var PageToSendTo = "https://ourvilla.net.au/pagevisited.php?" + VariablePlaceholder + MyVariable + MyPage + PageName;
window.open(PageToSendTo, 'InlineFrame1');//"_self")
//window.location.href = PageToSendTo;
return false;
}
The following is the final part of the PHP script itself
// Write record for visitors only
if (is_numeric($varVilla) )
{
// Now, format the output log record to be written to the file
$output = $today . "," . $varVilla . "," . $varUserName . "," . $user_ip . "," . $Device . "," . $City . "," . $Country . $logdata;

$file = fopen("villalog.csv","a");
fwrite($file,$output);
fclose($file);
}
The next function call is showTopic(htmlPage), for each button, the parameter is different, here is that function script
function showTopic(htmlPage)
{
pageName = htmlPage; // The argument here is passed from the onclick of the button calling it

var url = 'https://ourvilla.net.au/';
var goto = url.concat(pageName);
window.open(goto , 'InlineFrame1'); // Show the HTML page inside the iFrame

$('#Dialog1').dialog('open'); // The Dialog is initially hidden on page load
}
Is there any problem with this seup?
Should I have some sort of delay between the calls, to allow the first call to complete the writing to the file?
If so, how?

I am asking this because - if i Don't have the alert() - the php script doesn't execute and the 2nd function brings up the page

Thanks