This is my code
chrome.windows.create({'url': "http://example.com/upload/upload.php?pictureID="+ theResponse + "&userID=" + localStorage["id"]+"&username="+ localStorage["mainLogin"]}, function(tab) {
// open window
});
this constructs a URL that looks like:
http://example.com/upload/upload.php?pictureID=123&userID=1&username=jack
I would call this method GET -- like how forms GET or POST
How can I open a window with POST data rather than GET data?
I think you have to write a HTML page that creates a form containing your POST data and target URL and submit the form.
Here's a simple example:
<html>
<head>
<script>
document.addEventListener('DOMContentLoaded', function()
{
location.search.substr(1).split('&').forEach(function(item)
{
var input = document.createElement('input');
input.type = 'hidden';
input.name = item.substr(0, item.indexOf('='));
input.value = item.substr(item.indexOf('=') + 1);
document.getElementById('postform').appendChild(input);
});
document.getElementById('postform').submit();
});
</script>
</head>
<body>
<form action="http://example.com/upload/upload.php" method="post" id="postform">
</form>
</body>
</html>
Say that's test.html in your extension's root directory. Call
chrome.windows.create({'url': "test.html?pictureID="+ theResponse + "&userID=" + localStorage["id"]+"&username="+ localStorage["mainLogin"]}, function(tab) {
// open window
});
will open the website with POST method.
Related
I want to be able to send the page URL and open a page when clicking on a leaflet marker.
If you believe there are better alternatives to submit the LINK please provided it below and will be more than happy to try it.
I need help getting the URL sent on the FORM
page_template_mobile.php
<head>
<script>
// Variable containing page URL
var siteURL = location.href;
// When click on blue marker, send URL and go to page
function onClick(e) {
document.myform.submit();
}
//Start location marker
const marker = L.marker([0, 0]).on('click', onClick).addTo(map).bindTooltip("Click here to upload a picture",
{
permanent: true,
direction: 'right'
}
);
</script>
</head>
<body>
<form name="myform" action="/uas_tools/visualization_generator/V2/Resources/PHP/upload_picture.php" method="POST">
<input type="hidden" id="custId" name="custId" value=<script> siteURL </script>>
Search
</form>
</body>
upload_picture.php
<?php
$page_url = $_POST['custId'];
_log('page_url: ' .$page_url);
?>
This is how I solved
// Variable containing page URL
var siteURL = location.href;
// URL is saved on custId
document.getElementById("custId").value = siteURL;
<form name="myform" action="/uas_tools/visualization_generator/V2/Resources/PHP/upload_picture.php" method="POST">
<input type="hidden" id="custId" name="custId">
</form>
I'm trying to replace link from api, and redirect automatically to another link
Html code :
<html>
<body>
<p id="link"></p>
<script>
$.getJSON('api_url', function(data) {
document.getElementById("link").innerHTML = data.url;
});
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</body>
</html>
Api Result :
<p id="link"></p>
//example1.com/aaa/?k=0000
I want to replace this link
//example1.com/aaa/
With
//aaa.com/aaa/
And
Redirect to
https://aaa.com/aaa/?k=0000
hello did you try this below ?
var url = "//example1.com/aaa/?k=0000";
var url = url.replace("//example1.com/aaa/", "//aaa.com/aaa/");
window.location="https:"+url;
to get the link from your api result you can use :
var url = document.getElementById("link").innerHTML;
Try this
$.getJSON('api_url', function(data) {
var link=document.getElementById("link");
link.setAttribute('href', data.url);
link.click();
});
look ...
i have a server installed on a linux machine ( RHEL 7 + PHP ) . where i have a server called " Printer " acessible by : 192.168.0.48/Printer.
i have a page php at my server that create a file with some ZPL LANGUAGE inside on this location
' \Printer\documents\'
its possible to send the file that has been generated to the printers of side-client via " window.open() " ?
or for example , get the content of this file and insert of this function ?
<script type="text/javascript">
function printZpl(zpl) {
var printWindow = window.open();
printWindow.document.open('text/plain')
printWindow.document.write(zpl);
printWindow.document.close();
printWindow.focus();
printWindow.print();
printWindow.close();
}
</script>
You can pass string to encodeURIComponent() at function call and set string as .textContent of <pre> element at opened window to preserve new line characters for at print() call
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<button id="print">Print file</button>
<script type="text/javascript">
function printZpl(zpl) {
var printWindow = window.open(`data:text/html,<!DOCTYPE html><html><body><pre>${zpl}</pre><script>print();<\/script></body></html>`);
printWindow.focus();
}
var zpl = `^XA
^FXTest ZPL
^FS
^FO50,100
^A0N,89
^FDHello ZPL
^FS
^XZ`;
document.getElementById("print")
.onclick = function() {
printZpl(encodeURIComponent(zpl))
};
</script>
</body>
</html>
plnkr http://plnkr.co/edit/TBx0tNP0WkDODAz71qzO?p=preview
I have attempted to go about the use of Paypal Lightbox a bit differently.
I have used a button to trigger an ajax call which then generates the PayKey and if all goes well then triggers the form (from the documentation) to be created and submitted.
When i click the button the lightbox html is created but the content is not loaded into it. Instead i get the error:
Load denied by X-Frame-Options: https://www.sandbox.paypal.com/us/cgi-bin/webscr?cmd=_dispatch-failed does not permit cross-origin framing.
My Code:
<head>
<script src="https://www.paypalobjects.com/js/external/dg.js" type="text/javascript"></script>
</head>
External Script:
$("#checkout").click(function() {
var id = $(this).data("id");
if(id) { pay(id); }
});
function pay(id) {
$.ajax({
url : 'paypal/Pay-Chained.php',
type : 'POST',
data : "id="+id,
success : function (data) {
var info = (JSON.parse(data));
if (info['Type'] == 'Success') {
var output = info['URL'].substr(0, 64) + "expType=light&" + info['URL'].substr(64);
$("body").append('<form action="'+output+'" target="PPDGFrame" class="standard"><input type="submit" id="submitBtn"></form>');
$("#submitBtn").click();
} else {
alert("Error: Please try again or contact support.");
}
},
error : function () {
alert("Error: Please try again.");
}
});
}
At the bottom of the buttons page:
<script type="text/javascript" charset="utf-8">
var embeddedPPFlow = new PAYPAL.apps.DGFlow({trigger: 'checkout'});
</script>
I am thinking maybe it has to do with the order things are executed but can't seem to figure it out. Any help would be great!
EDIT: I just created a blank page and copied the script from the documentation exactly. I still get the same error. Might it have something to do with server settings? I am running a WampServer with an address like 192.168.1.1/mysite/index.html.
In my project I have the following script in order to open a page:
<script type="text/javascript">
function setPage(pName) {
var iPage = "'" + pName + "'";
document.getElementById('iFrame').src = window.location.href(iPage);
}
</script>
when I run the program it gives me the following problematic url:
Requested URL
http://localhost:7819/Pages/Account/'http:/localhost:7819/Pages/Support/Asp/Help01.aspx'
As we see the address contain the url of the current page plus the requested url.
More of it I'm loosing the second slash / in http:/ which I have it all the way inside the script.
How can I solve this issue?
I assume, you wanted something like this?
<script type="text/javascript">
function setPage(pName) {
document.getElementById('iFrame').src = pName;
}
</script>