Javascript linking with window.open - javascript

I am trying to give a link from my php page. But its showing an error. Is the following script correct? Can anyone help me pls? Its an annotation problem. Some where i have not put the annotation correctly?
window.open('add_new_shipment.php?tender_id='+result["tender_id"]&
id='+result["id"], 'quotation', 'scrollbars=yes', 'menubar=no', 'status=no', 'width=800, height=600');

Missing + ' Plus sign and single quote
window.open('add_new_shipment.php?tender_id='+result["tender_id"] +'&id='+result["id"], 'quotation', 'scrollbars=yes', 'menubar=no', 'status=no', 'width=800, height=600');
------^

var result = 50;
var id = 4;
window.open('add_new_shipment.php?tender_id='+result+'&'+'id='+id+',quotation,scrollbars=yes,menubar=no,status=no,width=800,height=600');
});
if you are using php in create url then use this script
window.open('add_new_shipment.php?tender_id=&id=,quotation,scrollbars=yes,menubar=no,status=no,width=800,height=600');
});

Related

Creating a variable and using it in HTML code in Google Scripts

Is there a way to use a variable in Google Scripts HTML Code? Right now I have:
var activeUser = Session.getActiveUser()
app.add(app.createHTML("<h1>Hello, activeUser </h1>"));
This doesn't work. Is there a way to make this work? Thanks!
Do you mean something like this?
var activeUser = Session.getActiveUser()
app.add(app.createHTML("<h1>Hello, " + activeUser + "</h1>"));

Thymleaf javascript variable combining

I'm using thymeleaf in my spring boot project. It's working well. Now I need to render one url in JavaScript as a string and need to concatenate with one JavaScript variable. I have tried the following code.
location.href = /*[[#{/signage/save}]]*/ '' + res.id
But the generated output is
location.href='/signage/save';
What I want is following
location.href = '/signage/save' + res.id;
How can I achieve it?
You can tell Thymeleaf to uncomment certain code if the page is served dynamically using special comment syntax /*[+...+]*/. And inside this commented block, you can put expressions and they will be evaluated together with the whole block.
/*[+ location.href = [[#{/signage/save}]] + res.id +]*/
Will be rendered as
location.href = '/signage/save' + res.id
After trying few methods got the solution, not exactly what I needed but it works for me. I just wrapped it using parenthesis ((.....))
location.href = (/*[[#{/signage/save}]]*/ '') + res.id
and generated output is
location.href = ('/signage/save') + res.id;

Embed a javascript variable into my html anchor href

I have a piece of HTML which should look something like the following when rendered by the browser:
<b>This is a test</b>Test over!
The problem I have is that foo.php is defined in a javascript var in the document. For argument sake, the name of the var is myPath. I'm trying to figure out how to get rid of the hard coded foo.php from the HTML above and have it read it from myPath instead.
I've tried different variations of escaping quotes and document.write() but haven't had much luck.
Is there a way to do something similar to:
<a href=" + myPath + "?bar=yay">
and have it render foo.php from myPath?
If you give your link an ID, you can use that in your JavaScript to reference the element and modify its href.
<a href="#" id="js_link">
And then your JavaScript could look something like this:
window.onload = function() {
var myPath = 'foo.php',
link = document.getElementById('js_link');
link.href = myPath;
}
Just use getElementByID then set the href property.
Check out this working example.
(function () {
var a = document.getElementById('mylink');
var fooLink = 'foo.php';
var link = fooLink + '?bar=yay';
a.href = link;
})();
You should be able to use inline script to output your javascript variable.
This might help How to output JavaScript with PHP

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;

Problem when I try to open file and write into it

Could somebody explain why the following simple script doesn't work in Firefox and how can I fix it?
<script type="text/javascript">
var w = window.open("a.php");
w.document.write("hello");
</script>
Thanks much
(edited to make the code sample display better)
DOM Scripting is more up to date and more robust.
e.g.
var w = window.open("a.php");
w.onload = function(){//you could also use dom ready rather than onload but that is a longer script that I've not included here
var body = w.document.getElementsByTagName("body")[0];
body.appendChild(document.createTextNode("bar"));
}
I'm pretty sure you can't read/ write files using javascript because it's a client side language? I may be completely wrong though!
EDIT:
Try this code:
var new_window, new_window_content = [];
new_window_content.push('<html><head><title>New Window</title></head>');
new_window_content.push('<body>New Window</body>');
new_window_content.push('</html>');
new_window = window.open("", "", "status,height=200,width=200");
new_window.document.write(new_window_content.join(''));
Cheers, Sean
To the others posting answers here: he is not trying to open a file and write to it - it is impossible in javascript in a browser. What he is instead trying to do with the w.document.write is to write to the end of the web page he has just opened in a browser.
Google Chrome says this code fails as:
>>> var w = window.open("http://www.google.co.uk");
undefined
>>> w.document.write("lol");
TypeError: Cannot call method 'write' of undefined
You first need to open the document stream by using document.open() - this will add a write function in w.document:
<script type="text/javascript">
var w = window.open("a.php");
w.document.open();
w.document.write("hello");
w.document.close();
</script>

Categories

Resources