I want to make sure that if a user clicks the button that opens a new window, that window is maintained if they click the button again. Meaning that I want the user to be able to hold multiple copies of the same window open even when opening new (of the same) ones.
At the moment I have this:
onclick="window.open('file.php?game=0', 'newwindow' , 'width=920,height=740', 'resizable=0')
and I read another thread on here that I could just add a counter.
I did so with
$counter = 0; and then put , 'counter++$apos;, as an argument but that fails to load the entire page.
What am I missing?
$counter is a variable … but it looks like a PHP variable.
'counter++' is a string literal.
If you want a new window each time you run the script, just use the name _blank. There's no point to giving the window a name of its own unless you want to open multiple links in the same window.
Related
I need to write new text in a p tag on the 'cart' page when I click on the 'submit' button on the 'index' page. How can I do this with JavaScript. I have already tried with this
HTML page index :
<button onclick="myFunction()"> click me </button>
HTML page cart :
<p id="id"> </p>
Js code :
function myFunction() {
document.getElementById('id').innerHtml = 'mytext';
}
but it does not work. How I can solve this? Thank you
index page and cart page in this reference, are different documents.
Accordingly, when you call your function on the index page, it can't find an element with the mentioned id in that document.
function myFunction() {
document.getElementById('id').innerHtml = 'mytext';
}
The only way to perform this trick with only Javascript, is to use Cookies.
You can create a Cookie in the client's browser and save 'mytext' as an object, then retrieve it on another page.
See this page https://www.w3schools.com/js/js_cookies.asp
If you're not using a SPA structure with a framework like React or Vue this could be difficult - however its not impossible.
What you can do to circumvent the issue is that you can save a variable in sessionStorage or localStorage depending on whether or not you want it to remain between different browser sessions, then in your other page check if this variable exists and if it does make the required changes.
Then when it should change back you remove the variable from your localStorage again.
It's a bit of a hacky way, and the best way would be to either do this server side or to have a SPA and share the variable through global state.
Description:
I created this workflow: PHP loads content from a database to certain textareas. The user can edit and save content.
I created a HTML template which can be printed directly from the web browser.
So the user clicks on the "Print" button and gets a nice template which can be printed directly from the browser.
Goal:
I want jQuery or JavaScript to load / transfer the content from the input fields to another HTML document on the server, in certain div-classes.
Is this generally possible or a good idea?
Afterwards, this becomes loaded and the print dialogue of the web browser will be opened.
Present Code:
$(document).ready(function() {
$( ".print-button" ).click(function() {
$('html').load("./views/print/template-1.html");
setTimeout(function(){
window.print();
}, 1000);
})
window.onafterprint = function(e){
$(window).off('mousemove', window.onafterprint);
window.location.href = window.location.href;
};
});
So template-1.html should get the data.
First of all I think it would be a good idea to support the build in functionality of the browser. The user should be able to hit Ctrl+P or use the menu to open the print dialog.
My suggestion would be to create a <div> element that is hidden. On some event, like when the <textarea> is changed, update the <div> element with the content. Create a stylesheet for printing where the <div> element is visible and hide elements that are not for printing (like the <textarea>).
As per the description, you have mentioned that you are allowing PHP to load the data in certain text-areas and allows user to update that, so when you update this data, it'll be saving into the database for that particular text-area.
What best you can do here is keep one unique key for that shown data and when you redirect the page bind the unique key along with the page URL, so using that key on the new page where you have the template, you can get the data using select query and you can print the data wherever you want.
Afterwords on print click, the template will have the data filled in and so the user will be able to download/print the template with data, the way you wanted.
Or
If you don't want to use the PHP for getting data on the new document, you can simply pass the data object in localstorage by using below way :
var content= <your data Object>;
localStorage.setItem('print_content', content);
Now before loading the dialogue, get the data from localstorage variable and print it to div or area wherever you want. For getting data from localstorage use below way:
var printData = localStorage.getItem('print_content');
using printData var, you'll be able to get the data and using jQuery syntax you'll be able to append or display the data to div.
I need to be able to change a domain variable (or set it if it's not already set) and then reload the page. I do not care if the page doesn't reload in fact I need it to reload.
For example if a user is on page: sample.com/demo?theme=theme1
and they select a new theme from the dropdown I want to change the theme variable to navigate the browser to the same page with the new domain variable, so in this case sample.com/demo?theme=newtheme.
I can't just do a standard redirect because I don't want them just going to the homepage I want them to stay on the current page just have the variable changed. For instance if they were here: sample.com/demo/aboutus?theme=theme1 then they would be sent here: sample.com/demo/aboutus?theme=newtheme
A simple regex would do:
window.location = window.location.url.replace(/(\?|&)theme=[^&]+/, '$1theme=newtheme');
Just make your anchor tag relative:
Theme 1
Theme 2
Theme 3
the only downside is the current querystring will be completely replaced with the new one, if that is even an issue.
This can of course be done with javascript too:
window.location = "?theme=theme1";
//window.location = "?theme=theme2";
//window.location = "?theme=theme3";
Here's what I'm using as a custom button control in Salesforce that executes JavaScript.
location.replace('/email/author/emailauthor.jsp?retURL=/{!Case.Id}&p3_lkid={!Case.Id}&rtype=003&p7=GetURLHere&p2_lkid={!Case.ContactId}&template_id=00Xc0000000HrOk');
The GetURLHere part is where I'd like to grab the current URL and place it on the next page.
This form works like Select Listview > Click Button > New page loads with the previous pages URL in the p7 field.
p7represents a field I'd like to put it into upon page load.
The usual document.location.hrefdoesn't want to work in this control.
Any idea on how to do this in the Force.com environment?
You should be able to use the $CurrentPage object to get the current pages url as a formula expression.
document.location.href = '{!$CurrentPage.URL}';
I try to explain better. I have one user control in page, and inside this have UC2 (modal pop up). And I try to achieve this: When I close UC2(modal) i try to update some fields on UC1. And this works fine for one(I have UC2(modal) and on button Save OnClientClick="SaveInfoCI()"), and in UC1 on top of page
function SaveInfoCI() {
document.getElementById("<%=frmData.FindControl("txtImplementingCI").ClientID%>").value
= document.getElementById("<%=UC2.GetClientID%>").value; }
but because i reuse this control in another place i want to update another field. Basically now i Have 3 JS function that update 3 fields. And I try when I click save in UC2(modal) I must execute one of this 3 javascript f, to update right field. I don't want to have 3 same UC with only difference in OnClientClick="SaveInfoCI().
Two problems: first, your syntax is off, when inside code behind you can't use the <%= like this.
Second problem, by the time this script is executed (on top of the page) the elements still does not exist. You have to change the value in the client side page load event.
So this should work, though it's better done server side:
sb.Append("window.onload = function() { document.getElementById('" + frmData.FindControl("txtTextBox").ClientID + "').value = document.getElementById('" + MyUserControl.GetJs + "').value; };</")
Also, you really don't need StringBuilder here.. use ordinary string instead.