Can't join 2 bits of javascript together to get bookmark to work.

M

MS

Hi,

The following bookmarklet is one I altered to use from the library lookup
project. Basically the 1st 2 lines of the code below extracts a book's
ISBN number (worldwide unique ID) from the book's page on a site like
Amazon. The next 3 lines open a new window on my local library's site with
the URL formatted like a GET posting of a form to do the search on the
library's site for the ISBN retrieved by the 1st 2 lines of code.

javascript:var%20re=/([\/-]|is[bs]n=)(\d{7,9}[\dX])/i;
if(re.test(location.href)==true){var%20isbn=RegExp.$2;
void(win=window.open('http://www.address.uk/bin/def?input='+isbn,
'LibraryLookup','scrollbars=1,resizable=1,
location=1,width=575,height=500'))}

This used to work perfectly, but now my library has changed their system
and the site will no longer accept a GET URL and requires a post.

jamie.ly in this forum showed be how to POST the data automatically, and
what I came up with is this:

javascript:'<body onload="document.forms[0].submit()">
<form Method="post" action="www.address.com/TP/doSearch.do">
<input name="searchType" value="advSearch" />
<input name="st1" value="controlNumber" />
<input name="sv1" value=isbn />
<input name="sb1" value="And" />
<input name="st2" value="title" />
<input name="sv2" value="" />
<input name="sb2" value="And" />
<input name="st3" value="author" />
<input name="sv3" value="" />
<input name="searchLocation" value="talislms" />
<input name="searchCollection" value="1" />
<input name="searchSites" value="-1" />
<input name="searchDates" value="" />
<input name="searchManualDate" value="" />
<input name="searchLanguages" value="" />
<input name="searchFormats" value="" />
<input name="searchOPUS" value="" />
<input name="pageSize" value="20" />
</form></body>'

When I merged the 2 bits of code together I ended up with a new window
opening showing my library's search page and then the form acting on the
original page, in this case a book page on Amazon's site. Obviously the
form to be posted needs to be done on the newly opened page (the library's
search page) and not on the Amazon page (which gave me a 404 as you'd expect).

Try as I might I can't work out how to join the 2 bits of code together
correctly, E.G. open a new window and once opened and loaded, run the form
code on it.

Can someone help please? Many thanks, and regards, etc..
 
D

David Mark

Hi,

The following bookmarklet is one I altered to use from the library lookup
project. Basically the 1st 2 lines of the code below extracts a book's
ISBN number (worldwide unique ID) from the book's page on a site like
Amazon. The next 3 lines open a new window on my local library's site with
the URL formatted like a GET posting of a form to do the search on the
library's site for the ISBN retrieved by the 1st 2 lines of code.

javascript:var%20re=/([\/-]|is[bs]n=)(\d{7,9}[\dX])/i;
if(re.test(location.href)==true){var%20isbn=RegExp.$2;
void(win=window.open('http://www.address.uk/bin/def?input='+isbn,
'LibraryLookup','scrollbars=1,resizable=1,
location=1,width=575,height=500'))}

This used to work perfectly, but now my library has changed their system
and the site will no longer accept a GET URL and requires a post.

jamie.ly in this forum showed be how to POST the data automatically, and
what I came up with is this:

javascript:'<body onload="document.forms[0].submit()">
<form Method="post" action="www.address.com/TP/doSearch.do">
<input name="searchType" value="advSearch" />
<input name="st1" value="controlNumber" />
<input name="sv1" value=isbn />
<input name="sb1" value="And" />
<input name="st2" value="title" />
<input name="sv2" value="" />
<input name="sb2" value="And" />
<input name="st3" value="author" />
<input name="sv3" value="" />
<input name="searchLocation" value="talislms" />
<input name="searchCollection" value="1" />
<input name="searchSites" value="-1" />
<input name="searchDates" value="" />
<input name="searchManualDate" value="" />
<input name="searchLanguages" value="" />
<input name="searchFormats" value="" />
<input name="searchOPUS" value="" />
<input name="pageSize" value="20" />
</form></body>'

When I merged the 2 bits of code together I ended up with a new window
opening showing my library's search page and then the form acting on the
original page, in this case a book page on Amazon's site.

The group FAQ has an example of how to submit a form to a child
window.
 
M

MS

(e-mail address removed) emailed this:
This doesn't seem like it will work. Was this what I showed you?


I think you're right, the form just gets displayed on the page with the
correct values already filled in, but it does not get submitted.


This is what you wrote before:

---------------------------------------------------------------
javascript:'<body onload="document.forms[0].submit()">
<form Method="post" action="/TalisPrism/doSearch.do">
<input name="searchType" value="advSearch" />
<input name="st1" value="controlNumber" />
<input name="sv1" value="0747566534" />
<input name="" ... >
</form></body>'

Does that make sense to you? Each ampersand separates a key and value
pair, delimited by an equals sign. Each of these pairs must be
created as an input element like I have done with the first three
pairs above. You can specify the value using the value attribute
which I have used in the input elements above.
---------------------------------------------------------------

I followed what you wrote and came up with this (latest version). However
despite adding target="LibraryLookup" to the form it still operates on the
original window and not the newly opened window, and the form gets
displayed not submitted.

Any ideas? Many, many, thanks, here's the code:


javascript:var re=/([\/-]|is[bs]n=)(\d{7,9}[\dX])/i;
if(re.test(location.href)==true){var isbn=RegExp.$2;

void(win=window.open('http://www.library.islington.gov.uk/TalisPrism/',
'LibraryLookup','scrollbars=1,resizable=1,location=1,width=575,height=500'));

'<body onload="document.forms[0].submit()"> <form Method="post"
action="www.library.islington.gov.uk/TalisPrism/doSearch.do"
target="LibraryLookup">
<input name="searchType" value="advSearch" />
<input name="st1" value="controlNumber" />
<input name="sv1" value="' + isbn + '" />
<input name="sb1" value="And" />
<input name="st2" value="title" />
<input name="sv2" value="" />
<input name="sb2" value="And" />
<input name="st3" value="author" />
<input name="sv3" value="" />
<input name="searchLocation" value="talislms" />
<input name="searchCollection" value="1" />
<input name="searchSites" value="-1" />
<input name="searchDates" value="" />
<input name="searchManualDate" value="" />
<input name="searchLanguages" value="" />
<input name="searchFormats" value="" />
<input name="searchOPUS" value="" />
<input name="pageSize" value="20" />
</form></body>';}
 
M

MS

MS emailed this:
(e-mail address removed) emailed this:


I think you're right, the form just gets displayed on the page with the
correct values already filled in, but it does not get submitted.

Update - it is now working !! Code below.

One problem, the form data gets POSTed to the new window automatically
('on load') and correctly, however the form itself is also displayed in
the old window, anyone know how to stop that happening?

Many thanks.


Library Look Up Project - Bookmarklet Code - Post Form Alteration:


javascript:var re=/([\/-]|is[bs]n=)(\d{7,9}[\dX])/i;
if(re.test(location.href)==true){var isbn=RegExp.$2;

void(win=window.open('http://www.library.islington.gov.uk/TalisPrism/',
'LibraryLookup','scrollbars=1,resizable=1,location=1,menubar=1,
toolbar=1,status=1,width=800,height=600'));

'<body onload="document.forms[0].submit()">
<form Method="post"
action="http://www.library.islington.gov.uk/TalisPrism/doSearch.do"
target="LibraryLookup">

<input name="searchType" value="advSearch" />
<input name="st1" value="controlNumber" />
<input name="sv1" value="' + isbn + '" />
<input name="sb1" value="And" />
<input name="st2" value="title" />
<input name="sv2" value="" />
<input name="sb2" value="And" />
<input name="st3" value="author" />
<input name="sv3" value="" />
<input name="searchLocation" value="talislms" />
<input name="searchCollection" value="1" />
<input name="searchSites" value="-1" />
<input name="searchDates" value="" />
<input name="searchManualDate" value="" />
<input name="searchLanguages" value="" />
<input name="searchFormats" value="" />
<input name="searchOPUS" value="" />
<input name="pageSize" value="20" />
<input type="submit" name="submitbutton" />
</form></body>';}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top