Ciprian
Ciprian

Reputation: 3226

Add more GET data for Javascript

I am using the javascript below to send information from one website to another, but I don't know how to add more data. ?url is fine. I'm not sure how to add more data to the javascript. I would like to add an ?img, a ?title ... i tried a few times but no luck. Help please.

JavaScript

 onclick="window.open('http://mysite.com/submit.?url='+(document.location.href));return false;"

PHP

$url = $_GET['url'];

Upvotes: 1

Views: 335

Answers (2)

Brad
Brad

Reputation: 163448

Separate the parameters with &.

http://mysite.com/submit?param1=value1&param2=value2&param3=value3

You should also encode your values with encodeURI().

Upvotes: 4

Dave Newton
Dave Newton

Reputation: 160261

You wouldn't add ?moreParm...etc, you use an ampersand (&) to add additional parameters.

var url = `http://mysite.com/submit.?url=' + document.location.href;
url += '&anotherParam=foo`;
// etc.

You need to escape all parameter values accordingly.

I'd also recommend moving it into a function so your embedded JS doesn't become impossible to read.

Upvotes: 0

Related Questions