0

Is it possible to append a string to url using the body? Something similar to the JSFiddle below.

http://jsfiddle.net/qXs77/

<a href="#" onclick="extendSearch('&page=2');return false">hi</a>

I want to append this query to the url: ?q1=iPodTouch&x=79&y=20

When the user clicks the link they will be taken to the next page with the attached string above.

1
  • Try putting location.href += "url: ?q1=iPodTouch&x=79&y=20" inside the onclick event Commented Feb 23, 2014 at 16:34

2 Answers 2

1

Updated :

No need to pass it on another function ,

Use like this:

<a href="http://xxxxxx.com/xx-xxxxxx" onclick="location.href = $(this).attr('href')+'?q1=iPodTouch&x=79&y=20';return false">Navigate</a>
Sign up to request clarification or add additional context in comments.

10 Comments

The string isn't attached to to the next page. I changed the href to the url of my site and there's no string.
it attached you can see it by opening jsfiddle result : As View Frame Source view-source:fiddle.jshell.net/_display/:%20?q1=iPodTouch&x=79&y=20
in the href I added a url but when I save and click the link it doesn't have the string
Which browser you use? my side both my DEMO works correctly..m using Chrome
I'm using Google Chrome
|
0

If you wanted to utilize jQuery more you could try this approach.

$('a[data-page]').on('click', function(e){
  e.preventDefault();
  var page = $(this).data('page');
  location.href += ( location.search.length ? '&' : '?' ) + 'page=' + page;
});

and have the HTML look like:

<a href="#" data-page="2">Page 2</a>

1 Comment

Does this attach to the url of the next page?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.