Search code examples
javascriptiosbookmarklet

Bookmarklet for iOS Rewrite URL and visit in Safari


I'm trying to automate a process I do manually. I visit webpages at the following url with different UserNo. I then have to individually copy and paste the UserNo into a new web address to search for it.

Example 1 of source URL

http://www. testdomain.com/ViewProfile.asp?UserNo=2978359&Keywords&Test=qw12&Var=Qatar

I would like to be able to click on a Bookmarklet bookmark that takes me from the above website to;

http://www .differentdomain.com/q=2978359

Example 2 of source URL

http://www .testdomain.com/ViewProfile.asp?UserNo=1123478&Keywords&Test=qw12&Var=Denmark

I want the Bookmarklet when clicked to take me to http://www .differentdomain.com/q=1123478

The UserNo is only numbers.

Thanks in advance

Mark


Solution

  • This solves the problem

    javascript:var%20q=document.location.href.match(/UserID=(.*?)(?=&|$)/i);{q=q[1];window.open('http://www.differentdomain.com/search?q='+q);}

    Or

    javascript:(function(){var%20q=document.location.href.match(/UserID=(.*?)(?=&|$)/i);q=q[1];window.open('http://google.com/search?q='+q);})();