javascript can't accept in output rewrite in views - javascript

I need to display the node title,node edit and node url.when user hits the node url means its open in popup window so for that i try to rewrite the output of that url field in views.First i create a new js file called popup.js include to via theme.info inside that file i paste the following code
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "','toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=1000,height=250,left = 12,top = 259');");
Then i move to output rewrite section add following code
view
But that url not open pop up window.is there any thing i missed.Any one point me my error.
thanks......

Try this in your js file
function popUp(URL) {
var day = new Date();
var id = day.getTime();
window.open(URL);
}
if it doesn't work then try to put the same code in you page.tpl.php file. Also try with chang the name of your callback form popUp() to other name. It may be conflicting with other callback.

Related

I am writing a script to copy a file Url to an Html Output. The issue I am having is the Url code has the text '?usp=drivesdk' added to the Url

My code to get the Url (from a new worksheet that has been copied)
DriveApp.getFileById(sheet.getId()).makeCopy(nom,destFolder).getUrl();
var htmlOutput = HtmlService.createHtmlOutput('' + fileUrl + '')
.setWidth(350).setHeight(50);
SpreadsheetApp.getUi().showModalDialog(htmlOutput,'Flowcalculator');
The Html shows the correct Url for the new file except it has an ending ....../edit?usp=drivesdk.
Do I need to write a 'format' function to delete the ?usp=drivesdk. or change the suffix to 'share' (I want the user to be able to open the file from the ModalDialog by clicking on the Url
I think that in your situation, even when https://docs.google.com/spreadsheets/d/{spreadsheetId}/edit?usp=drivesdk is used as the hyperlink for opening the Spreadsheet, the link can be used.
I thought that in your script, '' + fileUrl + '' is required to be modified. In this case, the URL is https://docs.google.com/spreadsheets/d/. This cannot be used.
If you want to open the copied Spreadsheet by clicking the link on the dialog, how about the following modification?
Modified script:
var fileUrl = DriveApp.getFileById(sheet.getId()).makeCopy(nom, destFolder).getUrl();
var htmlOutput = HtmlService.createHtmlOutput(`${fileUrl}`).setWidth(350).setHeight(50);
SpreadsheetApp.getUi().showModalDialog(htmlOutput, 'Flowcalculator');
In this case, please declare the variables of sheet, nom, and destFolder.
If you want to use https://docs.google.com/spreadsheets/d/{spreadsheetId}/edit?usp=sharing instead of https://docs.google.com/spreadsheets/d/{spreadsheetId}/edit?usp=drivesdk, please modify as follows.
From
var fileUrl = DriveApp.getFileById(sheet.getId()).makeCopy(nom, destFolder).getUrl();
To
var fileUrl = DriveApp.getFileById(sheet.getId()).makeCopy(nom, destFolder).getUrl().replace("drivesdk", "sharing");

How to make the variable not start new line

I am making a website where you have to input a link, and it makes javascript, but after imputing the variable, it adds a line so it doesn't work.
This is the code I am using
var url = prompt("Enter the link you want the app to go to.");
document.getElementById(2).onclick = "window.open('" + url + "', '_blank');'>";
Anyone got suggestions?
You just dont need to use these strings to set url variable in window.open method.
You could try this:
var url = prompt("Enter the link you want the app to go to.");
document.getElementById(2).onclick = () => window.open(url, '_blank');
I think what you want to do is something like that
var url = prompt("Enter the link you want the app to go to.");
if(url){
document.getElementById("xxxx").onclick=function(){
window.open(url, '_blank');
}
}
Quickest fix: First remove that stray <, as #audiodude said. Then use the function constructor.
var url = prompt("Enter the link you want the app to go to.");
document.getElementById(2).onclick = new Function("window.open('" + url + "', '_blank');")

JQuery Using passed parameter value to initialize a page via $(document).ready

I am trying to access or make a parameter value which was passed via an <a> visible within another javascript file. I can't figure out how to go about it.
I have the ff. line of code which goes to a new page: student_learn_topiclink.php everytime the link is clicked
var topicLink = $('<a>' + topicTitle+ '</a>').addClass('topic_link').attr('href','view/student_learn_topiclink.php?topicId=' + topicId).attr('target','_blank');
This is what shows in the address bar after clicking the topicLink
http://localhost/cai/view/student_learn_topiclink.php?topicId=5
I want to use the value 5 in student_learn_topiclink page's JS file.
How can I expose or make the topicId = 5 visible in student_learn_topiclink JS file?
In student_learn_topiclink.js, I'd like to do something like this,
$(document).ready(function(){
alert(topicId);
});
See this thread about retrieving URL parameters with javascript. For your specific example, try the following:
var url_string = window.location.href;
var url = new URL(url_string);
var topicId = url.searchParams.get("topicId");
console.log(topicId);
Example fiddle: http://jsfiddle.net/craftman32/yxrvbcun/1/
You can use like this :
var topicId = window.location.search.split('topicId=')[1];
console.log(topicId);

How to call a trusted function from acroform

I have been looking for an example of how to call a trusted function in acroforms and havent found any. I am trying to build a form for my company that will allow users to click a button and automatically have the form save to a folder on our server (eg: //SERVER1/Forms/). I found this code to test with and placed it in C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\Javascripts
//SaveAs Function1
var date = new Date();
var day = date.getDate();
var month = date.getMonth()+1;
var year = date.getFullYear();
var dateSigned = String(month) + String(day) + String(year);
var mySaveDoc = app.trustedFunction(function(doc,fileNam­e){
app.beginPriv();
var myPath = "C/test/" + fileName + "Agreement " + dateSigned + ".pdf";
//saveAs is the only privileged code that needs to be enclosed
doc.saveAs({cPath: myPath, bCopy: true, bPromptToOverwrite: false});
//doc.close();
app.endPriv();
});
Any help on making this work is greatly appreciated!!
I think the location of the application level script is correct; check whether you have other files in that folder; one of them would be a precompiled one, coming from Adobe.
Now, for calling the trusted function, well…, call it as you would call any other function:
mySaveDoc(this, fileName) ;
and that should do it.
However, there are a few issues I don't like that much in the application-level script:
The dateSigned variable and its bits and pieces will be defined and initialized when the application starts, and then keep their value. In other words, if you keep Reader running all the time, the date will not be updated. To get the current date all the time, you'd have to initialize the dateSigned variable within the function. AND, as you are in Acrobat JavaScript, you can use the util object for assembling the string.
Your script would then look like this:
var mySaveDoc = app.trustedFunction(function(doc, fileName){
app.beginPriv() ;
var dateSigned = util.printd("MMDDYYYY", new Date() ;
var myPath = "/C/test" + filename + "Agreement " + dateSigned + ".pdf" ;
doc.saveAs({cPath: myPath, bCopy: true, bPromptToOverwrite: false}) ;
app.endPriv() ;
}) ;
Note that there is als a slash at the beginning of the path (although I may be wrong on that; as I don't have access to a Windows machine, I can not verify it; if someone else would use Acrobat, open any file, and then run this.path() from the Console, then he could confirm the slash (or not)).

How to add an variable value in between the hyperlink in javascript

I am sending an email via javascript. In mail.parameter.text property I need to send the hyperlink. In the code below I am hardcoding the url whick looks very lengthy and also I need to add the /dashboard at the end of the url. Any idea on how to shorten the url?
var parent = space.getParent();
var siteGroup = "GROUP_EMAIL_CONTRIBUTORS";
var mail = actions.create("mail");
mail.parameters.to_many = siteGroup;
mail.parameters.subject="New Site Created in Community"
mail.parameters.text=" A new site called " + document.properties.name +"is created.Click http://pc1:8080/share/page/site/"+document.properties.name+"/dashboard"+" to join the site";
//execute action against a document
mail.execute(document);
Sorry if this is a basic question I dont know javascript. This is my entire script and I am not using any html tags in between.
You can change it to something like this, for example:
mail.parameters.text="Click <a href='http://pc1:8080/share/page/site/" + document.properties.name + "/dashboard'>here</a>";
Your link will appear as "here" and nevertheless lead to the URL you specified. Is that what you mean by "shorten the url"?
Please try now.
var url = "Click http://pc1:8080/share/page/site/" + document.properties.name + "/dashboard" + " to join the site";
ail.parameters.text = url;

Categories

Resources