1

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'];
Community
  • 1
  • 1
Ciprian
  • 3,066
  • 9
  • 62
  • 98

2 Answers2

4

Separate the parameters with &.

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

You should also encode your values with encodeURI().

Community
  • 1
  • 1
Brad
  • 159,648
  • 54
  • 349
  • 530
  • The only addition I have is to use an encoded `&` for what will be outputted to the browser. – Jared Farrish Nov 05 '11 at 20:34
  • @JaredFarrish, this is in JavaScript, not HTML. Escaping HTML entities is irrelevant here. – Brad Nov 05 '11 at 20:35
  • Even though it's in an `onclick` attribute handler? (Which is what I was thinking.) – Jared Farrish Nov 05 '11 at 20:36
  • @JaredFarrish, Oh, in that case, you are correct. I missed that part, I assumed he was going to put this in a script somewhere. – Brad Nov 05 '11 at 20:37
  • @Brad `http://mysite.com/submit.?url='+(document.location.href)&title=+(document.title));` so as you probably guessed I suck at Javascript. Can you please give me an example? I've tried to change the code a few times without any luck. What I'm trying to do is grab the url and title of a page and use it in wordpress to create a new post.So a `$title = $_GET['title'];` will also be used. Thank you – Ciprian Nov 06 '11 at 08:44
  • @ciprian, Try this: `'http://mysite.com/submit?url=' + encodeURIComponent(document.location.href) + '&title=' + encodeURIComponent(document.title)` The `+` symbol is used for concatenation (sticking two strings together) in JavaScript, so you must put that in between everything you want to concatenate. – Brad Nov 14 '11 at 14:17
0

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.

Dave Newton
  • 158,873
  • 26
  • 254
  • 302